r232786 - Don't crash-on-valid when an inline function is friend of class template
David Majnemer
david.majnemer at gmail.com
Thu Mar 19 17:02:27 PDT 2015
Author: majnemer
Date: Thu Mar 19 19:02:27 2015
New Revision: 232786
URL: http://llvm.org/viewvc/llvm-project?rev=232786&view=rev
Log:
Don't crash-on-valid when an inline function is friend of class template
We assumed that the most recent declaration of an inline function would
also be inline. However, a more recent declaration can come from a
friend declaration in a class template that is instantiated at the
definition of the function.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/CodeGenCXX/inline-functions.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=232786&r1=232785&r2=232786&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Mar 19 19:02:27 2015
@@ -7911,7 +7911,7 @@ static GVALinkage basicGVALinkageForFunc
// Functions specified with extern and inline in -fms-compatibility mode
// forcibly get emitted. While the body of the function cannot be later
// replaced, the function definition cannot be discarded.
- if (FD->getMostRecentDecl()->isMSExternInline())
+ if (FD->isMSExternInline())
return GVA_StrongODR;
return GVA_DiscardableODR;
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=232786&r1=232785&r2=232786&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Mar 19 19:02:27 2015
@@ -2734,7 +2734,8 @@ bool FunctionDecl::isMSExternInline() co
if (!Context.getLangOpts().MSVCCompat && !hasAttr<DLLExportAttr>())
return false;
- for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDecl())
+ for (const FunctionDecl *FD = getMostRecentDecl(); FD;
+ FD = FD->getPreviousDecl())
if (FD->getStorageClass() == SC_Extern)
return true;
Modified: cfe/trunk/test/CodeGenCXX/inline-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/inline-functions.cpp?rev=232786&r1=232785&r2=232786&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/inline-functions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/inline-functions.cpp Thu Mar 19 19:02:27 2015
@@ -121,3 +121,18 @@ struct TypeWithInlineMethods {
// CHECK-NOT: _ZN21TypeWithInlineMethods12NonStaticFunEv
void NonStaticFun() { StaticFun(); }
};
+
+namespace PR22959 {
+template <typename>
+struct S;
+
+S<int> Foo();
+
+template <typename>
+struct S {
+ friend S<int> Foo();
+};
+
+__attribute__((used)) inline S<int> Foo() { return S<int>(); }
+// CHECK-LABEL: define linkonce_odr void @_ZN7PR229593FooEv(
+}
More information about the cfe-commits
mailing list