Skip to content

Commit a6c3949

Browse files
committed
[CIR] Make the asserts to display suggestion for -fno-clangir-call-conv-lowering
While here, add more unrecheables to cover some of the current errors, so that our users can see a clear message instead of a random cast assert of sorts. This covers at least all crashes seen when removing -fno-clangir-call-conv-lowering from all tests, there are probably other things we'll find as we exercise this path.
1 parent b130f71 commit a6c3949

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

clang/include/clang/CIR/MissingFeatures.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef CLANG_CIR_MISSINGFEATURES_H
1616
#define CLANG_CIR_MISSINGFEATURES_H
1717

18+
#include <llvm/Support/raw_ostream.h>
19+
1820
constexpr bool cirMissingFeatureAssertionMode =
1921
true; // Change to `false` to use llvm_unreachable
2022

@@ -24,9 +26,15 @@ constexpr bool cirMissingFeatureAssertionMode =
2426
" point."
2527

2628
// Special assertion to be used in the target lowering library.
27-
#define cir_tl_assert(cond) assert((cond) && NOTE);
29+
#define cir_tl_assert(cond) \
30+
do { \
31+
if (!(cond)) \
32+
llvm::errs() << NOTE << "\n"; \
33+
assert((cond)); \
34+
} while (0)
2835

29-
// Special
36+
// Special version of cir_unreachable to give more info to the user on how
37+
// to temporaruly disable target lowering.
3038
#define cir_unreachable(msg) \
3139
do { \
3240
llvm_unreachable(msg NOTE); \

clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
5151
continue;
5252
}
5353

54-
auto callOp = cast<CallOp>(call.getUser());
54+
auto callOp = dyn_cast_or_null<CallOp>(call.getUser());
55+
if (!callOp)
56+
cir_unreachable("NYI empty callOp");
5557
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
5658
return failure();
5759
}

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ Value castReturnValue(Value Src, Type Ty, LowerFunction &LF) {
210210
if (isa<BoolType>(SrcTy) && isa<IntType>(Ty))
211211
return createBitcast(Src, Ty, LF);
212212

213+
auto intTy = dyn_cast<IntType>(Ty);
214+
if (intTy && !intTy.isPrimitive())
215+
cir_unreachable("non-primitive types NYI");
213216
llvm::TypeSize DstSize = LF.LM.getDataLayout().getTypeAllocSize(Ty);
214217

215218
// FIXME(cir): Do we need the EnterStructPointerForCoercedAccess routine here?

0 commit comments

Comments
 (0)