mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-29 14:06:12 +00:00

Instead of relying on whether a certain identifier is a builtin, introduce BuiltinAttr to specify a declaration as having builtin semantics. This fixes incompatible redeclarations of builtins, as reverting the identifier as being builtin due to one incompatible redeclaration would have broken rest of the builtin calls. Mostly-compatible redeclarations of builtins also no longer have builtin semantics. They don't call the builtin nor inherit their attributes. A long-standing FIXME regarding builtins inside a namespace enclosed in extern "C" not being recognized is also addressed. Due to the more correct handling attributes for builtin functions are added in more places, resulting in more useful warnings. Tests are updated to reflect that. Intrinsics without an inline definition in intrin.h had `inline` and `static` removed as they had no effect and caused them to no longer be recognized as builtins otherwise. A pthread_create() related test is XFAIL-ed, as it relied on it being recognized as a builtin based on its name. The builtin declaration syntax is too restrictive and doesn't allow custom structs, function pointers, etc. It seems to be the only case and fixing this would require reworking the current builtin syntax, so this seems acceptable. Fixes PR45410. Reviewed By: rsmith, yutsumi Differential Revision: https://reviews.llvm.org/D77491
41 lines
1.1 KiB
C
41 lines
1.1 KiB
C
// FIXME: pthread_create() definition in Builtins.def doesn't match the real one, so it doesn't get recognized as a builtin and attributes aren't added.
|
|
// RUN: false
|
|
// XFAIL: *
|
|
|
|
// RUN: %clang_cc1 %s -S -emit-llvm -o - -disable-llvm-optzns | FileCheck %s
|
|
|
|
// CHECK: declare !callback ![[cid:[0-9]+]] {{.*}}i32 @pthread_create
|
|
// CHECK: ![[cid]] = !{![[cidb:[0-9]+]]}
|
|
// CHECK: ![[cidb]] = !{i64 2, i64 3, i1 false}
|
|
|
|
// Taken from test/Analysis/retain-release.m
|
|
//{
|
|
struct _opaque_pthread_t {};
|
|
struct _opaque_pthread_attr_t {};
|
|
typedef struct _opaque_pthread_t *__darwin_pthread_t;
|
|
typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t;
|
|
typedef __darwin_pthread_t pthread_t;
|
|
typedef __darwin_pthread_attr_t pthread_attr_t;
|
|
|
|
int pthread_create(pthread_t *, const pthread_attr_t *,
|
|
void *(*)(void *), void *);
|
|
//}
|
|
|
|
const int GlobalVar = 0;
|
|
|
|
static void *callee0(void *payload) {
|
|
return payload;
|
|
}
|
|
|
|
static void *callee1(void *payload) {
|
|
return payload;
|
|
}
|
|
|
|
void foo() {
|
|
pthread_t MyFirstThread;
|
|
pthread_create(&MyFirstThread, 0, callee0, 0);
|
|
|
|
pthread_t MySecondThread;
|
|
pthread_create(&MySecondThread, 0, callee1, (void *)&GlobalVar);
|
|
}
|