Skip to content

Commit adb4afd

Browse files
ghehgsmeenai
authored andcommitted
[CIR][CIRGen][Builtin] Allow CIRGen for builtin calls with math errorno override (llvm#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() llvm#1 { call void @abort(), !dbg !8 ret void }` which is not right, right code should be like, ` `define dso_local void @test() llvm#1 { call void @abort(), !dbg !8 unreachable }` ` Still send this PR as Noreturn implementation is a separate issue.
1 parent bf23b40 commit adb4afd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
337337
// '#pragma float_control(precise, on)'. This pragma disables fast-math,
338338
// which implies math-errno.
339339
if (E->hasStoredFPFeatures()) {
340-
llvm_unreachable("NYI");
340+
FPOptionsOverride OP = E->getFPFeatures();
341+
if (OP.hasMathErrnoOverride())
342+
ErrnoOverriden = OP.getMathErrnoOverride();
341343
}
342344
// True if 'atttibute__((optnone)) is used. This attibute overrides
343345
// fast-math which implies math-errno.
@@ -1627,4 +1629,4 @@ mlir::cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
16271629

16281630
auto Ty = getTypes().ConvertType(FD->getType());
16291631
return GetOrCreateCIRFunction(Name, Ty, D, /*ForVTable=*/false);
1630-
}
1632+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t.ll
4+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
5+
6+
void abort();
7+
void test() { abort(); }
8+
9+
// TODO: Add test to test unreachable when CIR support for NORETURN is added.
10+
11+
// CIR-LABEL: test
12+
// CIR: cir.call @abort() : () -> ()
13+
14+
// LLVM-LABEL: test
15+
// LLVM: call void @abort()

0 commit comments

Comments
 (0)