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

fix: get llvm type of global val #128820

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<'ll> CodegenCx<'ll, '_> {
let val_llty = self.val_ty(v);

let g = self.get_static_inner(def_id, val_llty);
let llty = self.val_ty(g);
let llty = llvm::LLVMGlobalGetValueType(g);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also adjust the self.val_ty(g) != self.type_ptr() check above? That one is also supposed to read LLVMGlobalGetValueType(g) != llty I believe.

Copy link
Contributor Author

@LYF1999 LYF1999 Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... i found the initializer type is always a packed struct(val_llty) at now. which can never be equal to the llty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we use cx.const_struct(&llvals, true) to create a packed const struct at const_alloc_to_llvm. can we create a normal struct for static initializer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... i found the initializer type is always a packed struct(val_ty) at now. which can never be equal to the llty.

But isn't this also the type we pass as llty? It's the type of the initializer v above, which should also be a packed struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the llty is the type of old global var, which is set at predefine_static. and the val_llty is the type of initializer v.
the llty won't be a packed struct


let g = if val_llty == llty {
g
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ extern "C" {
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
pub fn LLVMGlobalGetValueType(Global: &Value) -> &Type;

// Operations on global variables
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
Expand Down
Loading