Skip to content

Commit e20931b

Browse files
[clang] Restrict Inline Builtin to non-static, non-odr linkage
Inline builtins have a very special behavior compared to other functions, it's better if we keep them restricted to a minimal set of functions. Add a linkage check which prevents considering ODR definitions as inline builtins. Fix llvm#62958 Differential Revision: https://reviews.llvm.org/D148723
1 parent 752f9d0 commit e20931b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,8 +3314,23 @@ bool FunctionDecl::isInlineBuiltinDeclaration() const {
33143314
return false;
33153315

33163316
const FunctionDecl *Definition;
3317-
return hasBody(Definition) && Definition->isInlineSpecified() &&
3318-
Definition->hasAttr<AlwaysInlineAttr>();
3317+
if (!hasBody(Definition))
3318+
return false;
3319+
3320+
if (!Definition->isInlineSpecified() ||
3321+
!Definition->hasAttr<AlwaysInlineAttr>())
3322+
return false;
3323+
3324+
ASTContext &Context = getASTContext();
3325+
switch (Context.GetGVALinkageForFunction(this)) {
3326+
case GVA_Internal:
3327+
case GVA_DiscardableODR:
3328+
case GVA_StrongODR:
3329+
return false;
3330+
case GVA_AvailableExternally:
3331+
case GVA_StrongExternal:
3332+
return true;
3333+
}
33193334
}
33203335

33213336
bool FunctionDecl::isDestroyingOperatorDelete() const {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple x86_64-windows -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
2+
// Inline builtin are not supported for odr linkage
3+
// CHECK-NOT: .inline
4+
5+
double __cdecl frexp( double _X, int* _Y);
6+
inline __attribute__((always_inline)) long double __cdecl frexpl( long double __x, int *__exp ) {
7+
return (long double) frexp((double)__x, __exp );
8+
}
9+
10+
long double pain(void)
11+
{
12+
long double f = 123.45;
13+
int i;
14+
long double f2 = frexpl(f, &i);
15+
return f2;
16+
}

0 commit comments

Comments
 (0)