[PATCH] CodeGen: Emit some functions as weak_odr under -fms-extensions
David Majnemer
david.majnemer at gmail.com
Thu Mar 27 16:47:01 PDT 2014
@rsmith: They have the "special" behavior for templates but only specializations matter, the primary template is not considered:
template <typename T> inline void fun(T x);
template <> extern inline void fun(int) {}
However, this is refused by clang:
> explicit specialization has extraneous, inconsistent storage class 'extern'
@rnk: If mingw people are using `-fms-extensions`, they will not be effected at all in the C language mode because we require linkage to be `GVA_CXXInline`; those people will continue to get either their C99 or GNU semantics. They would only be effected if the used C++ or `__inline`. AFAICT, this extension is conforming if surprising.
================
Comment at: lib/AST/Decl.cpp:2587
@@ +2586,3 @@
+// the function to be required.
+bool FunctionDecl::isMSExternInline() const {
+ const ASTContext &Context = getASTContext();
----------------
Richard Smith wrote:
> You've put this between the helper function `RedeclForcesDefC99` and the function that uses it; move it up above that function, please!
Will do, sorry about that!
================
Comment at: lib/AST/Decl.cpp:2596
@@ +2595,3 @@
+ do {
+ IsInlineSpecified |= FD->isInlineSpecified();
+ IsExternSpecified |= FD->getStorageClass() == SC_Extern;
----------------
Richard Smith wrote:
> I assume the idea here is to compute whether any declaration has the `inline` keyword and to exclude the case where `inline` was implied by `constexpr` or by being defined inside a class definition. Please add tests for those cases.
Sure, will do.
================
Comment at: lib/AST/Decl.cpp:2598-2599
@@ +2597,4 @@
+ IsExternSpecified |= FD->getStorageClass() == SC_Extern;
+ if (IsInlineSpecified && IsExternSpecified)
+ break;
+ } while ((FD = FD->getPreviousDecl()));
----------------
Richard Smith wrote:
> Do we really hit this special case if the `extern` and `inline` keywords are on different declarations? (Again, add a test case please!)
Sure, will add some tests.
================
Comment at: lib/CodeGen/CodeGenModule.cpp:558
@@ +557,3 @@
+
+ // Functions specified with extern and inline in -fmicrosoft-extensions mode
+ // forcibly get emitted. While the body of the function cannot be later
----------------
Reid Kleckner wrote:
> s/-fmicrosoft-extensions/-fms-extensions/
Done.
================
Comment at: test/CodeGen/inline.c:55
@@ -54,2 +54,3 @@
// RUN: echo "MS C Mode tests:"
// RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-optzns -emit-llvm -o - -std=c99 -fms-compatibility | FileCheck %s --check-prefix=CHECK4
+// CHECK4-LABEL: define weak_odr i32 @ei()
----------------
Reid Kleckner wrote:
> This is -fms-compatibility. Does that imply -fms-extensions?
Yep.
http://llvm-reviews.chandlerc.com/D3207
More information about the cfe-commits
mailing list