Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[globalopt] optimization leaves store to a constant global #42961

Open
aqjune opened this issue Oct 9, 2019 · 0 comments
Open

[globalopt] optimization leaves store to a constant global #42961

aqjune opened this issue Oct 9, 2019 · 0 comments
Labels
bugzilla Issues migrated from bugzilla ipo Interprocedural optimizations miscompilation

Comments

@aqjune
Copy link
Contributor

aqjune commented Oct 9, 2019

Bugzilla Link 43616
Version trunk
OS All
Attachments input
CC @aqjune,@LebedevRI,@preames,@nunoplopes

Extended Description

$ opt -version
LLVM (http://llvm.org/):
  LLVM version 10.0.0svn
  Optimized build with assertions.
  Default target: x86_64-apple-darwin19.0.0
  Host CPU: skylake

$ cat input.ll
declare {}* @​llvm.invariant.start.p0i8(i64 %size, i8* nocapture %ptr)

define void @​test1(i8* %ptr) {
  call {}* @​llvm.invariant.start.p0i8(i64 4, i8* %ptr)
  ret void
}

@​object1 = global i32 0
define void @​ctor1() {
  store i32 -1, i32* @​object1
  %A = bitcast i32* @​object1 to i8*
  call void @​test1(i8* %A)
  ret void
}

@​llvm.global_ctors = appending constant
  [1 x { i32, void ()*, i8* }]
  [ { i32, void ()*, i8* } { i32 65535, void ()* @​ctor1, i8* null } ]

$ opt -globalopt -S -o - input.ll
@​object1 = constant i32 -1
@​llvm.global_ctors = appending constant [0 x { i32, void ()*, i8* }] zeroinitializer

; Function Attrs: argmemonly nounwind willreturn
declare {}* @​llvm.invariant.start.p0i8(i64 immarg, i8* nocapture) #​0

define void @​test1(i8* %ptr) local_unnamed_addr {
  %1 = call {}* @​llvm.invariant.start.p0i8(i64 4, i8* %ptr)
  ret void
}

define void @​ctor1() local_unnamed_addr {
  store i32 -1, i32* @​object1
  %A = bitcast i32* @​object1 to i8*
  call void @​test1(i8* %A)
  ret void
}

attributes #​0 = { argmemonly nounwind willreturn }

Running -globalopt leaves a store to @​object1, which is a constant global, which may cause crash because LangRef states that it can be placed in the read-only section of an executable.

LangRef says:
A variable may be defined as a global constant, which indicates that the contents of the variable will never be modified (enabling better optimization, allowing the global data to be placed in the read-only section of an executable, etc).

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla ipo Interprocedural optimizations miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants