r282710 - Revert "[PR30341] Alias must point to a definition"

Aditya Kumar via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 29 04:37:23 PDT 2016


Author: hiraditya
Date: Thu Sep 29 06:37:23 2016
New Revision: 282710

URL: http://llvm.org/viewvc/llvm-project?rev=282710&view=rev
Log:
Revert "[PR30341] Alias must point to a definition"

This reverts commit r282679.

Ninja check fails, reverting to debug the issue.

Removed:
    cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=282710&r1=282709&r2=282710&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Sep 29 06:37:23 2016
@@ -134,11 +134,6 @@ bool CodeGenModule::TryEmitDefinitionAsA
   llvm::GlobalValue::LinkageTypes TargetLinkage =
       getFunctionLinkage(TargetDecl);
 
-  // available_externally definitions aren't real definitions, so we cannot
-  // create an alias to one.
-  if (TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage)
-    return true;
-
   // Check if we have it already.
   StringRef MangledName = getMangledName(AliasDecl);
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -161,7 +156,14 @@ bool CodeGenModule::TryEmitDefinitionAsA
 
   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
+     (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
+      !TargetDecl.getDecl()->hasAttr<AlwaysInlineAttr>())) {
+    // FIXME: An extern template instantiation will create functions with
+    // linkage "AvailableExternally". In libc++, some classes also define
+    // members with attribute "AlwaysInline" and expect no reference to
+    // be generated. It is desirable to reenable this optimisation after
+    // corresponding LLVM changes.
     addReplacement(MangledName, Aliasee);
     return false;
   }

Removed: cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp?rev=282709&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp (removed)
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -O1 -std=c++11 -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
-// Clang should not generate alias to available_externally definitions.
-// Check that the destructor of Foo is defined.
-// CHECK: define linkonce_odr void @_ZN3FooD2Ev
-template <class CharT>
-struct String {
-  String() {}
-  ~String();
-};
-
-template <class CharT>
-inline __attribute__((visibility("hidden"), always_inline))
-String<CharT>::~String() {}
-
-extern template struct String<char>;
-
-struct Foo : public String<char> { Foo() { String<char> s; } };
-
-Foo f;




More information about the cfe-commits mailing list