Skip to content

Commit 5ab8010

Browse files
committed
[CIR] Change default assumption about allowing builtins
The code to read the "nobuiltins" attributes hasn't been implemented yet, but we were defaulting to the assumption that use of builtins is allowed for function calls that we recognize as standard C library calls and have builtin equivalents of. This change reverses that assumption so that when such calls are encountered, we just emit the call. This is a better default assumption, and since our builtin handling for these functions isn't implemented yet, it also allows us to compile more programs.
1 parent e1bb35d commit 5ab8010

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ CIRGenCallee CIRGenFunction::emitDirectCallee(const GlobalDecl &gd) {
10521052

10531053
bool isPredefinedLibFunction =
10541054
cgm.getASTContext().BuiltinInfo.isPredefinedLibFunction(builtinID);
1055-
bool hasAttributeNoBuiltin = false;
1055+
// Assume nobuiltins everywhere until we actually read the attributes.
1056+
bool hasAttributeNoBuiltin = true;
10561057
assert(!cir::MissingFeatures::attributeNoBuiltin());
10571058

10581059
// When directing calling an inline builtin, call it through it's mangled

clang/test/CIR/CodeGen/libc.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
// Note: In the final implementation, we will want these to generate
5+
// CIR-specific libc operations. This test is just a placeholder
6+
// to make sure we can compile these to normal function calls
7+
// until the special handling is implemented.
8+
9+
void *memcpy(void *, const void *, unsigned long);
10+
void testMemcpy(void *dst, const void *src, unsigned long size) {
11+
memcpy(dst, src, size);
12+
// CHECK: cir.call @memcpy
13+
}
14+
15+
void *memmove(void *, const void *, unsigned long);
16+
void testMemmove(void *src, const void *dst, unsigned long size) {
17+
memmove(dst, src, size);
18+
// CHECK: cir.call @memmove
19+
}
20+
21+
void *memset(void *, int, unsigned long);
22+
void testMemset(void *dst, int val, unsigned long size) {
23+
memset(dst, val, size);
24+
// CHECK: cir.call @memset
25+
}
26+
27+
double fabs(double);
28+
double testFabs(double x) {
29+
return fabs(x);
30+
// CHECK: cir.call @fabs
31+
}
32+
33+
float fabsf(float);
34+
float testFabsf(float x) {
35+
return fabsf(x);
36+
// CHECK: cir.call @fabsf
37+
}
38+
39+
int abs(int);
40+
int testAbs(int x) {
41+
return abs(x);
42+
// CHECK: cir.call @abs
43+
}
44+
45+
long labs(long);
46+
long testLabs(long x) {
47+
return labs(x);
48+
// CHECK: cir.call @labs
49+
}
50+
51+
long long llabs(long long);
52+
long long testLlabs(long long x) {
53+
return llabs(x);
54+
// CHECK: cir.call @llabs
55+
}

0 commit comments

Comments
 (0)