Skip to content

Commit ee010a2

Browse files
committed
[Clang] Adjust exit() builtin impl
- `_Exit` is an alias to `_exit` and `_exit` is declared in unistd.h header, so don't mix `_Exit` and `exit`. Only `exit` decl placed in stdlib.h. - Add `__builtin_` variants for exit functions like GCC does
1 parent a6a462f commit ee010a2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,9 +2660,10 @@ def Calloc : LibBuiltin<"stdlib.h"> {
26602660
}
26612661

26622662
def Exit : LibBuiltin<"stdlib.h"> {
2663-
let Spellings = ["exit", "_Exit"];
2663+
let Spellings = ["exit"];
26642664
let Attributes = [NoReturn];
26652665
let Prototype = "void(int)";
2666+
let AddBuiltinPrefixedAlias = 1;
26662667
}
26672668

26682669
def Malloc : LibBuiltin<"stdlib.h"> {
@@ -3266,9 +3267,10 @@ def StrnCaseCmp : GNULibBuiltin<"strings.h"> {
32663267
}
32673268

32683269
def GNU_Exit : GNULibBuiltin<"unistd.h"> {
3269-
let Spellings = ["_exit"];
3270+
let Spellings = ["_exit", "_Exit"];
32703271
let Attributes = [NoReturn];
32713272
let Prototype = "void(int)";
3273+
let AddBuiltinPrefixedAlias = 1;
32723274
}
32733275

32743276
def VFork : LibBuiltin<"unistd.h"> {

clang/test/CodeGen/attributes.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ void t24(f_t f1) {
113113
(*p)();
114114
}
115115

116+
// CHECK:define{{.*}} void @t25() [[NUW]] {
117+
// CHECK: call void @exit(i32 noundef 1)
118+
// CHECK-NEXT: unreachable
119+
void t25(void) {
120+
__builtin_exit(1);
121+
}
122+
123+
// CHECK:define{{.*}} void @t26() [[NUW]] {
124+
// CHECK: call void @_exit(i32 noundef 2)
125+
// CHECK-NEXT: unreachable
126+
void t26(void) {
127+
__builtin__exit(2);
128+
}
129+
130+
// CHECK:define{{.*}} void @t27() [[NUW]] {
131+
// CHECK: call void @_Exit(i32 noundef 3)
132+
// CHECK-NEXT: unreachable
133+
void t27(void) {
134+
__builtin__Exit(3);
135+
}
136+
116137
// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
117138
// CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} }
118139
// CHECK: attributes [[COLDDEF]] = { cold {{.*}}}

0 commit comments

Comments
 (0)