Repository navigation
Don't use llvm_type as the type of statics. - #165371
Conversation
bae9652 to
9b707b8
Compare
|
Wouldn't this just cause the logic at rust/compiler/rustc_codegen_llvm/src/consts.rs Lines 497 to 528 in ae36fe2 |
|
This PR causes that logic to run less, not more. Initializers don't have the type of the variable - they're just an of array of bytes interspersed with pointers and arrays of undef. In the case of an initializer with no undef or pointers, the initializer type will be |
There was a problem hiding this comment.
One question, if you agree it's not a problem then r=me
This runs the risk of tripping up all sorts of LLVM tests, this one seems the most likely to me
@bors try jobs=test-x86_64-gnu-nopt
There was a problem hiding this comment.
I've renamed them to actual_global and pointer_global respectively.
| // A64-NEXT: ldr {{[a-z0-9]+}}, {{\[}}[[REG2]]{{\]}} | ||
| #[no_mangle] | ||
| pub fn mango() -> u8 { | ||
| unsafe { *EXOCHORDA } |
There was a problem hiding this comment.
curiously, mangoes are not in exochorda.
Anyway, are we worried about this additional instruction? The docs note that the address given to ldr
Is the optional positive immediate byte offset, a multiple of 8 in the range 0 to 32760, defaulting to 0.
So I guess the address of EXOCHORDA is not longer appropriately aligned? Which, I suppose it was by luck before given that u8 has an alignment of 1 anyway?
There was a problem hiding this comment.
The ldr is the load of the *mut u8 itself (which is the type of the static), the u8 is loaded by a ldrb afterwards. I'm guessing LLVM is presuming the static has an alignment based on the default alignment of the type of the static - this seems incorrect as BackendRepr::Scalar doesn't provide any alignment guarantees. This PR incidentally fixes this by always using a type with an alignment of 1 - I think not fixing this would mean that miscompilations would occur after #159033 is merged.
There was a problem hiding this comment.
The LangRef says
An explicit alignment may be specified for a global, which must be a power of 2. If not present, or if the alignment is set to zero, the alignment of the global is set by the target to whatever it feels convenient.
which isn't especially reassuring. This PR is an improvement upon the status quo, but is there any reason we don't set an explicit alignment on global declarations?
There was a problem hiding this comment.
There is no reason as far as I am aware of, and I know most all of the other curses in this area. Globals should receive explicitly-specified alignments for the same reason everything else gets explicitly-specified alignments.
This comment has been minimized.
This comment has been minimized.
Don't use `llvm_type` as the type of `static`s. try-job: test-x86_64-gnu-nopt
9b707b8 to
aff3637
Compare
|
Per #165371 (review) @bors r=folkertdev |
…rtdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…rtdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…uwer Rollup of 15 pull requests Successful merges: - #165378 (rustfmt subtree update (v1.12.0)) - #149245 (Make inline attributes apply to the generated `poll` in async fn) - #164304 ([perf] Reuse CanonicalVarKinds if no new variables were added) - #165109 (Avoid building a region map when erasing bound regions) - #163393 (std: Use getexecpath() for current_exe() on OpenBSD) - #164896 (offload: pass the linked device image to the host pass) - #165358 (Reenable some cg_gcc tests that were disabled) - #165371 (Don't use `llvm_type` as the type of `static`s.) - #162232 (Replace `builtin #` with `k#`) - #162608 (Avoid oscillating line wrapping due to symbol indices) - #165029 (Use `MalformedLintAttributeInput` in more places) - #165203 (AIX: Implement TLS destructor guard in std and update dynamic-loading-cdylib test) - #165230 (Fix rigidity assertion ICE) - #165354 (Remove `AbiAlign`) - #165374 (Refactorings in preparation for the move trait)
…rtdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…uwer Rollup of 14 pull requests Successful merges: - #165378 (rustfmt subtree update (v1.12.0)) - #149245 (Make inline attributes apply to the generated `poll` in async fn) - #164304 ([perf] Reuse CanonicalVarKinds if no new variables were added) - #165109 (Avoid building a region map when erasing bound regions) - #163393 (std: Use getexecpath() for current_exe() on OpenBSD) - #164896 (offload: pass the linked device image to the host pass) - #165358 (Reenable some cg_gcc tests that were disabled) - #165371 (Don't use `llvm_type` as the type of `static`s.) - #162232 (Replace `builtin #` with `k#`) - #162608 (Avoid oscillating line wrapping due to symbol indices) - #165029 (Use `MalformedLintAttributeInput` in more places) - #165203 (AIX: Implement TLS destructor guard in std and update dynamic-loading-cdylib test) - #165230 (Fix rigidity assertion ICE) - #165374 (Refactorings in preparation for the move trait)
…rtdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…uwer Rollup of 14 pull requests Successful merges: - #149245 (Make inline attributes apply to the generated `poll` in async fn) - #164304 ([perf] Reuse CanonicalVarKinds if no new variables were added) - #165109 (Avoid building a region map when erasing bound regions) - #163393 (std: Use getexecpath() for current_exe() on OpenBSD) - #164896 (offload: pass the linked device image to the host pass) - #165358 (Reenable some cg_gcc tests that were disabled) - #165371 (Don't use `llvm_type` as the type of `static`s.) - #162232 (Replace `builtin #` with `k#`) - #162608 (Avoid oscillating line wrapping due to symbol indices) - #164241 (make the safety documentation consistent in Ptr module) - #165029 (Use `MalformedLintAttributeInput` in more places) - #165203 (AIX: Implement TLS destructor guard in std and update dynamic-loading-cdylib test) - #165230 (Fix rigidity assertion ICE) - #165374 (Refactorings in preparation for the move trait)
…rtdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…uwer Rollup of 13 pull requests Successful merges: - #149245 (Make inline attributes apply to the generated `poll` in async fn) - #164304 ([perf] Reuse CanonicalVarKinds if no new variables were added) - #165109 (Avoid building a region map when erasing bound regions) - #163393 (std: Use getexecpath() for current_exe() on OpenBSD) - #165358 (Reenable some cg_gcc tests that were disabled) - #165371 (Don't use `llvm_type` as the type of `static`s.) - #162232 (Replace `builtin #` with `k#`) - #162608 (Avoid oscillating line wrapping due to symbol indices) - #164241 (make the safety documentation consistent in Ptr module) - #165029 (Use `MalformedLintAttributeInput` in more places) - #165203 (AIX: Implement TLS destructor guard in std and update dynamic-loading-cdylib test) - #165230 (Fix rigidity assertion ICE) - #165374 (Refactorings in preparation for the move trait)
|
Rollup failure #165403 (comment) probably caused by this PR? |
|
This pull request was unapproved. |
This comment has been minimized.
This comment has been minimized.
Don't use `llvm_type` as the type of `static`s. try-job: test-aarch64-msvc-1
|
Yes seems likely. I wonder if we can make that test use minicore somehow? |
aff3637 to
bc082a3
Compare
|
@bors try cancel |
|
Try build cancelled. Cancelled workflows: Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run |
|
@bors try jobs=test-aarch64-msvc-1 |
This comment has been minimized.
This comment has been minimized.
Don't use `llvm_type` as the type of `static`s. try-job: test-aarch64-msvc-1
|
@bors r=folkertdev |
…uwer Rollup of 7 pull requests Successful merges: - #165416 (fix unsoundness when compiling `[diverging_const; 0]`) - #163217 ([perf] rustdoc: Avoid re-HIR-ty-lowering tys & const args where possible) - #165371 (Don't use `llvm_type` as the type of `static`s.) - #165354 (Remove `AbiAlign`) - #165357 (rustdoc: Fix invalid clean of paths when they end with `self`) - #165401 (Add codegen test for step_by(1) loop vectorization) - #165408 (LLVMRustWriteOutputFile: Check the result of runCodeGenPipeline)
Rollup merge of #165371 - beetrees:global-llvm-type, r=folkertdev Don't use `llvm_type` as the type of `static`s. This PR replaces the two uses of `llvm_type` as the type of `static`s - only the size of the static matters, so `cx.type_array(cx.type_i8(), layout.size)` is sufficient. As `static`s have to be redefined if the initialiser type is not the same as the existing type. using an LLVM `i8` array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes. r? @folkertdev
…uwer Rollup of 7 pull requests Successful merges: - rust-lang/rust#165416 (fix unsoundness when compiling `[diverging_const; 0]`) - rust-lang/rust#163217 ([perf] rustdoc: Avoid re-HIR-ty-lowering tys & const args where possible) - rust-lang/rust#165371 (Don't use `llvm_type` as the type of `static`s.) - rust-lang/rust#165354 (Remove `AbiAlign`) - rust-lang/rust#165357 (rustdoc: Fix invalid clean of paths when they end with `self`) - rust-lang/rust#165401 (Add codegen test for step_by(1) loop vectorization) - rust-lang/rust#165408 (LLVMRustWriteOutputFile: Check the result of runCodeGenPipeline)

View all comments
This PR replaces the two uses of
llvm_typeas the type ofstatics - only the size of the static matters, socx.type_array(cx.type_i8(), layout.size)is sufficient. Asstatics have to be redefined if the initialiser type is not the same as the existing type. using an LLVMi8array here is more optimal as it means the static type already matches the initializer in cases where the initializer is just plain bytes.r? @folkertdev