Skip to content

Commit

Permalink
[CIR] Make the asserts to display suggestion for -fno-clangir-call-co…
Browse files Browse the repository at this point in the history
…nv-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.
  • Loading branch information
bcardosolopes committed Oct 15, 2024
1 parent b130f71 commit a6c3949
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef CLANG_CIR_MISSINGFEATURES_H
#define CLANG_CIR_MISSINGFEATURES_H

#include <llvm/Support/raw_ostream.h>

constexpr bool cirMissingFeatureAssertionMode =
true; // Change to `false` to use llvm_unreachable

Expand All @@ -24,9 +26,15 @@ constexpr bool cirMissingFeatureAssertionMode =
" point."

// Special assertion to be used in the target lowering library.
#define cir_tl_assert(cond) assert((cond) && NOTE);
#define cir_tl_assert(cond) \
do { \
if (!(cond)) \
llvm::errs() << NOTE << "\n"; \
assert((cond)); \
} while (0)

// Special
// Special version of cir_unreachable to give more info to the user on how
// to temporaruly disable target lowering.
#define cir_unreachable(msg) \
do { \
llvm_unreachable(msg NOTE); \
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
continue;
}

auto callOp = cast<CallOp>(call.getUser());
auto callOp = dyn_cast_or_null<CallOp>(call.getUser());
if (!callOp)
cir_unreachable("NYI empty callOp");
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
return failure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ Value castReturnValue(Value Src, Type Ty, LowerFunction &LF) {
if (isa<BoolType>(SrcTy) && isa<IntType>(Ty))
return createBitcast(Src, Ty, LF);

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

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

0 comments on commit a6c3949

Please sign in to comment.