Summary: This diff changes the translation of global variables to translate the initializer whenever it exists in LLVM, rather than relying on linkage. Previously code such as ``` char *mutable_string = "hahaha"; ``` would lead to LLVM code ``` nutritious_string = global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), align 8, !dbg !0 ; [#uses=2 type=i8**] ``` in which `mutable_string` had `External` linkage according to `Llvm.linkage` even though it has an initializer. This could cause sledge to drop the initializer. Reviewed By: kren1 Differential Revision: D15577755 fbshipit-source-id: 50aa06c5emaster
parent
00c5e1b9fe
commit
babe25fd29
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2019-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
char* mutable_string = "a string";
|
||||
const char* immutable_string = "a string";
|
||||
|
||||
int mutable_int = 0;
|
||||
const int immutable_int = 0;
|
||||
|
||||
int main() {
|
||||
int mi = mutable_int;
|
||||
int imi = immutable_int;
|
||||
char* c = mutable_string;
|
||||
char a_char = *mutable_string;
|
||||
char b_char = *immutable_string;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue