Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GlobalOpt] Check stored once value's type before setting global init…
…ializer In the provided test case, we were trying to set the global's initializer to `i32* null` when the global's value type was `@0`. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D108232
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; RUN: opt -passes=globalopt < %s -S | FileCheck %s | ||
|
||
; Check that we don't try to set a global initializer to a value of a different type. | ||
; In this case, we were trying to set @0's initializer to be i32* null. | ||
|
||
%0 = type { i32* } | ||
|
||
@0 = internal global %0* null | ||
; CHECK: global %0 undef | ||
|
||
define void @a() { | ||
%1 = tail call i8* @_Znwm(i64 8) | ||
%2 = bitcast i8* %1 to %0* | ||
%3 = getelementptr inbounds %0, %0* %2, i64 0, i32 0 | ||
store i32* null, i32** %3, align 8 | ||
store i8* %1, i8** bitcast (%0** @0 to i8**), align 8 | ||
%4 = load i64*, i64** bitcast (%0** @0 to i64**), align 8 | ||
%5 = load atomic i64, i64* %4 acquire, align 8 | ||
ret void | ||
} | ||
|
||
declare i8* @_Znwm(i64) |