[llvm] r255123 - Change hasUniqueInitializer() to call isStrongDefinitionForLinker() instead of !isWeakForLinker()
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 9 08:17:08 PST 2015
Author: mehdi_amini
Date: Wed Dec 9 10:17:07 2015
New Revision: 255123
URL: http://llvm.org/viewvc/llvm-project?rev=255123&view=rev
Log:
Change hasUniqueInitializer() to call isStrongDefinitionForLinker() instead of !isWeakForLinker()
Summary:
Available_externally global variable with initializer were considered "hasInitializer()",
while obviously it can't match the description:
Whether the global variable has an initializer, and any changes made to the
initializer will turn up in the final executable.
since modifying the initializer of an externally available variable does not make sense.
Reviewers: pcc, rafael
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15351
From: Mehdi Amini <mehdi.amini at apple.com>
Added:
llvm/trunk/test/Transforms/GlobalOpt/available_externally_global_ctors.ll
Modified:
llvm/trunk/include/llvm/IR/GlobalVariable.h
Modified: llvm/trunk/include/llvm/IR/GlobalVariable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalVariable.h?rev=255123&r1=255122&r2=255123&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalVariable.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalVariable.h Wed Dec 9 10:17:07 2015
@@ -105,18 +105,13 @@ public:
/// hasUniqueInitializer - Whether the global variable has an initializer, and
/// any changes made to the initializer will turn up in the final executable.
inline bool hasUniqueInitializer() const {
- return hasInitializer() &&
- // It's not safe to modify initializers of global variables with weak
- // linkage, because the linker might choose to discard the initializer and
- // use the initializer from another instance of the global variable
- // instead. It is wrong to modify the initializer of a global variable
- // with *_odr linkage because then different instances of the global may
- // have different initializers, breaking the One Definition Rule.
- !isWeakForLinker() &&
- // It is not safe to modify initializers of global variables with the
- // external_initializer marker since the value may be changed at runtime
- // before C++ initializers are evaluated.
- !isExternallyInitialized();
+ return
+ // We need to be sure this is the definition that will actually be used
+ isStrongDefinitionForLinker() &&
+ // It is not safe to modify initializers of global variables with the
+ // external_initializer marker since the value may be changed at runtime
+ // before C++ initializers are evaluated.
+ !isExternallyInitialized();
}
/// getInitializer - Return the initializer for this global variable. It is
Added: llvm/trunk/test/Transforms/GlobalOpt/available_externally_global_ctors.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/available_externally_global_ctors.ll?rev=255123&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/available_externally_global_ctors.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/available_externally_global_ctors.ll Wed Dec 9 10:17:07 2015
@@ -0,0 +1,22 @@
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; RUN: opt -S -globalopt < %s | FileCheck %s
+
+; Verify that the initialization of the available_externally global is not eliminated
+; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo_static_init, i8* null }]
+
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo_static_init, i8* null }]
+ at foo_external = available_externally global void ()* null
+
+define internal void @foo_static_init() {
+entry:
+ store void ()* @foo_impl, void ()** @foo_external
+ ret void
+}
+
+define internal void @foo_impl() {
+entry:
+ ret void
+}
+
More information about the llvm-commits
mailing list