Skip to content

Commit

Permalink
[StructuralHash] Ignore global variable declarations
Browse files Browse the repository at this point in the history
Ignore declarations of global variables, just as we do with declarations
of functions.

Done as a follow up to the comments in https://reviews.llvm.org/D149209

Differential Revision: https://reviews.llvm.org/D153855

# Conflicts:
#	llvm/lib/IR/StructuralHash.cpp
  • Loading branch information
mikaelholmen committed Jun 29, 2023
1 parent 80155cb commit d2640f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/IR/StructuralHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit d2640f5

Please sign in to comment.