Skip to content

Commit

Permalink
[CIR][CIRGen][Builtin] Allow CIRGen for builtin calls with math error…
Browse files Browse the repository at this point in the history
…no override (#893)

As title. 
The test case used is abort(), but it is from the real code. 
Notice: Since CIR implementation for NoReturn Call is pending to
implement, the generated llvm code is like:
`define dso_local void @test() #1  {
  call void @abort(), !dbg !8
  ret void
}`
which is not right, right code should be like, 
`
`define dso_local void @test() #1  {
  call void @abort(), !dbg !8
  unreachable
}`
`
Still send this PR as Noreturn implementation is a separate issue.
  • Loading branch information
ghehg authored Sep 27, 2024
1 parent fe5310b commit 599dc51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
// '#pragma float_control(precise, on)'. This pragma disables fast-math,
// which implies math-errno.
if (E->hasStoredFPFeatures()) {
llvm_unreachable("NYI");
FPOptionsOverride OP = E->getFPFeatures();
if (OP.hasMathErrnoOverride())
ErrnoOverriden = OP.getMathErrnoOverride();
}
// True if 'atttibute__((optnone)) is used. This attibute overrides
// fast-math which implies math-errno.
Expand Down Expand Up @@ -1627,4 +1629,4 @@ mlir::cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD,

auto Ty = getTypes().ConvertType(FD->getType());
return GetOrCreateCIRFunction(Name, Ty, D, /*ForVTable=*/false);
}
}
15 changes: 15 additions & 0 deletions clang/test/CIR/CodeGen/builtin-abort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM

void abort();
void test() { abort(); }

// TODO: Add test to test unreachable when CIR support for NORETURN is added.

// CIR-LABEL: test
// CIR: cir.call @abort() : () -> ()

// LLVM-LABEL: test
// LLVM: call void @abort()

0 comments on commit 599dc51

Please sign in to comment.