diff --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp index 25a43810ad027..ca58cf9e718a4 100644 --- a/llvm/lib/IR/StructuralHash.cpp +++ b/llvm/lib/IR/StructuralHash.cpp @@ -58,9 +58,10 @@ class StructuralHashImpl { } void update(const GlobalVariable &GV) { - // used/compiler.used don't affect analyses. + // Declarations and used/compiler.used don't affect analyses. // Same for llvm.embedded.object, which is always a metadata section. - if (GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used" || + if (GV.isDeclaration() || + GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used" || GV.getName() == "llvm.embedded.object") return; hash(23456); // Global header diff --git a/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll b/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll new file mode 100644 index 0000000000000..c6ffd23cc23d2 --- /dev/null +++ b/llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll @@ -0,0 +1,9 @@ +; RUN: opt -passes=strip-dead-prototypes -S -verify-analysis-invalidation < %s | FileCheck %s + +; The declaration of the unused global variable @.str should be removed without +; getting any error from -verify-analysis-invalidation. + +; CHECK-NOT: @.str + +@.str = external constant [15 x i16] +