[cfe-commits] r69756 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclAttr.cpp test/CodeGen/inline.c test/Sema/function.c

Chris Lattner sabre at nondot.org
Tue Apr 21 17:03:31 PDT 2009


Author: lattner
Date: Tue Apr 21 19:03:30 2009
New Revision: 69756

URL: http://llvm.org/viewvc/llvm-project?rev=69756&view=rev
Log:
Fix some mishandling of the attr(gnu_inline) mode when used with
extern.  Previously we would warn about it and ignore the attribute.
This is incorrect, it should be handled as a c89 "extern inline" 
function.  Many thanks to Matthieu Castet for pointing this out and
beating me over the head until I got it.

PR3988: extern inline function are not externally visible



Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/CodeGen/inline.c
    cfe/trunk/test/Sema/function.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69756&r1=69755&r2=69756&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 21 19:03:30 2009
@@ -414,8 +414,6 @@
 def warn_gnu_inline_attribute_requires_inline : Warning<
   "'gnu_inline' attribute requires function to be marked 'inline',"
   " attribute ignored">;
-def warn_gnu_inline_attribute_extern_inline : Warning<
- "'gnu_inline' attribute is overridden by 'extern inline', attribute ignored">;
 
 def warn_attribute_ignored_for_field_of_type : Warning<
   "%0 attribute ignored for field of type %1">;

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69756&r1=69755&r2=69756&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 21 19:03:30 2009
@@ -238,30 +238,27 @@
   if (!FD->isInline())
     return CodeGenModule::GVA_StrongExternal;
   
-  // If the inline function explicitly has the GNU inline attribute on it, then
-  // force to GNUC semantics (which is strong external), regardless of language.
-  if (FD->hasAttr<GNUInlineAttr>())
+  // If the inline function explicitly has the GNU inline attribute on it, or if
+  // this is C89 mode, we use to GNU semantics.
+  if (FD->hasAttr<GNUInlineAttr>() || (!Features.C99 && !Features.CPlusPlus)) {
+    // extern inline in GNU mode is like C99 inline.
+    if (FD->getStorageClass() == FunctionDecl::Extern)
+      return CodeGenModule::GVA_C99Inline;
+    // Normal inline is a strong symbol.
     return CodeGenModule::GVA_StrongExternal;
+  }
 
   // The definition of inline changes based on the language.  Note that we
   // have already handled "static inline" above, with the GVA_Internal case.
   if (Features.CPlusPlus)  // inline and extern inline.
     return CodeGenModule::GVA_CXXInline;
   
-  if (FD->getStorageClass() == FunctionDecl::Extern) {
-    // extern inline in C99 is a strong definition. In C89, it is extern inline.
-    if (Features.C99)
-      return CodeGenModule::GVA_StrongExternal;
-    
-    // In C89 mode, an 'extern inline' works like a C99 inline function.
-    return CodeGenModule::GVA_C99Inline;
-  }
-  
-  if (Features.C99)
-    return CodeGenModule::GVA_C99Inline;
+  assert(Features.C99 && "Must be in C99 mode if not in C89 or C++ mode");
+  // extern inline in C99 is a strong definition.
+  if (FD->getStorageClass() == FunctionDecl::Extern) 
+    return CodeGenModule::GVA_StrongExternal;
   
-  // Otherwise, this is the GNU inline extension in K&R and GNU C89 mode.
-  return CodeGenModule::GVA_StrongExternal;
+  return CodeGenModule::GVA_C99Inline;
 }
 
 /// SetFunctionDefinitionAttributes - Set attributes for a global.

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=69756&r1=69755&r2=69756&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Apr 21 19:03:30 2009
@@ -1474,11 +1474,6 @@
     return;
   }
   
-  if (Fn->getStorageClass() == FunctionDecl::Extern) {
-    S.Diag(Attr.getLoc(), diag::warn_gnu_inline_attribute_extern_inline);
-    return;
-  }
-  
   d->addAttr(::new (S.Context) GNUInlineAttr());
 }
 

Modified: cfe/trunk/test/CodeGen/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/inline.c?rev=69756&r1=69755&r2=69756&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/inline.c (original)
+++ cfe/trunk/test/CodeGen/inline.c Tue Apr 21 19:03:30 2009
@@ -6,6 +6,7 @@
 // RUN: grep "define void @unreferenced1()" %t &&
 // RUN: not grep unreferenced2 %t &&
 // RUN: grep "define void @gnu_inline()" %t &&
+// RUN: grep "define available_externally void @gnu_ei_inline()" %t &&
 
 // RUN: echo "\nC99 tests:" &&
 // RUN: clang %s -emit-llvm -S -o %t -std=c99 &&
@@ -15,6 +16,7 @@
 // RUN: not grep unreferenced1 %t &&
 // RUN: grep "define void @unreferenced2()" %t &&
 // RUN: grep "define void @gnu_inline()" %t &&
+// RUN: grep "define available_externally void @gnu_ei_inline()" %t &&
 
 // RUN: echo "\nC++ tests:" &&
 // RUN: clang %s -emit-llvm -S -o %t -std=c++98 &&
@@ -22,7 +24,8 @@
 // RUN: grep "define linkonce_odr i32 @_Z3foov()" %t &&
 // RUN: grep "define i32 @_Z3barv()" %t &&
 // RUN: not grep unreferenced %t &&
-// RUN: grep "define void @_Z10gnu_inlinev()" %t
+// RUN: grep "define void @_Z10gnu_inlinev()" %t &&
+// RUN: grep "define available_externally void @_Z13gnu_ei_inlinev()" %t
 
 extern inline int ei() { return 123; }
 
@@ -37,3 +40,8 @@
 extern inline void unreferenced2() {}
 
 __inline __attribute((__gnu_inline__)) void gnu_inline() {}
+
+// PR3988
+extern inline __attribute__((gnu_inline)) void gnu_ei_inline() {}
+void (*P)() = gnu_ei_inline;
+

Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=69756&r1=69755&r2=69756&view=diff

==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Tue Apr 21 19:03:30 2009
@@ -64,7 +64,7 @@
 
 
 extern __inline
-__attribute__((__gnu_inline__))  // expected-warning{{'gnu_inline' attribute is overridden by 'extern inline', attribute ignored}} expected-warning{{extension used}}
+__attribute__((__gnu_inline__))  // expected-warning{{extension used}}
 void gnu_inline1() {}
 
 void





More information about the cfe-commits mailing list