about summary refs log tree commit diff
path: root/src/test/codegen
AgeCommit message (Collapse)AuthorLines
2021-12-12Stabilize asm! and global_asm!Amanieu d'Antras-27/+44
They are also removed from the prelude as per the decision in https://github.com/rust-lang/rust/issues/87228. stdarch and compiler-builtins are updated to work with the new, stable asm! and global_asm! macros.
2021-12-09Add test for issue #91490Nikita Popov-0/+14
2021-12-08add // compile-flags: -O to test that depends on optsErik Desjardins-0/+2
2021-12-05Attach range metadata to alignment loads from vtablesErik Desjardins-0/+43
...because alignment is always nonzero. This helps eliminate redundant runtime alignment checks, when a DST is a field of a struct whose remaining fields have alignment 1.
2021-12-05Rollup merge of #91355 - alexcrichton:stabilize-thread-local-const, r=m-ou-seMatthias Krüger-2/+0
std: Stabilize the `thread_local_const_init` feature This commit is intended to follow the stabilization disposition of the FCP that has now finished in #84223. This stabilizes the ability to flag thread local initializers as `const` expressions which enables the macro to generate more efficient code for accessing it, notably removing runtime checks for initialization. More information can also be found in #84223 as well as the tests where the feature usage was removed in this PR. Closes #84223
2021-12-03limit may_unwind codegen test to x86_64cynecx-0/+1
2021-12-03fix inline asm test because of missing attributecynecx-1/+1
2021-12-03add tests for asm's options(may_unwind)cynecx-0/+24
2021-12-02Auto merge of #91003 - psumbera:sparc64-abi, r=nagisabors-1/+57
fix sparc64 ABI for aggregates with floating point members Fixes #86163
2021-12-01Review commentsJamie Cunliffe-4/+4
- Changed the separator from '+' to ','. - Moved the branch protection options from -C to -Z. - Additional test for incorrect branch-protection option. - Remove LLVM < 12 code. - Style fixes. Co-authored-by: James McGregor <james.mcgregor2@arm.com>
2021-12-01Add codegen option for branch protection and pointer authentication on AArch64James McGregor-0/+41
The branch-protection codegen option enables the use of hint-space pointer authentication code for AArch64 targets
2021-12-01fix sparc64 ABI for aggregates with floating point membersPetr Sumbera-1/+57
2021-11-29std: Stabilize the `thread_local_const_init` featureAlex Crichton-2/+0
This commit is intended to follow the stabilization disposition of the FCP that has now finished in #84223. This stabilizes the ability to flag thread local initializers as `const` expressions which enables the macro to generate more efficient code for accessing it, notably removing runtime checks for initialization. More information can also be found in #84223 as well as the tests where the feature usage was removed in this PR. Closes #84223
2021-11-22add rustc option for using LLVM stack smash protectionBenjamin A. Bjørnseth-0/+34
LLVM has built-in heuristics for adding stack canaries to functions. These heuristics can be selected with LLVM function attributes. This patch adds a rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use of these attributes. This gives rustc the same stack smash protection support as clang offers through options `-fno-stack-protector`, `-fstack-protector`, `-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the current list of rustc exploit mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html), originally discussed in #15179. Stack smash protection adds runtime overhead and is therefore still off by default, but now users have the option to trade performance for security as they see fit. An example use case is adding Rust code in an existing C/C++ code base compiled with stack smash protection. Without the ability to add stack smash protection to the Rust code, the code base artifacts could be exploitable in ways not possible if the code base remained pure C/C++. Stack smash protection support is present in LLVM for almost all the current tier 1/tier 2 targets: see test/assembly/stack-protector/stack-protector-target-support.rs. The one exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a warning message printed if stack smash protection is used with this target (see test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3 targets has not been checked. Since the heuristics are applied at the LLVM level, the heuristics are expected to add stack smash protection to a fraction of functions comparable to C/C++. Some experiments demonstrating how Rust code is affected by the different heuristics can be found in test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is potential for better heuristics using Rust-specific safety information. For example it might be reasonable to skip stack smash protection in functions which transitively only use safe Rust code, or which uses only a subset of functions the user declares safe (such as anything under `std.*`). Such alternative heuristics could be added at a later point. LLVM also offers a "safestack" sanitizer as an alternative way to guard against stack smashing (see #26612). This could possibly also be included as a stack-protection heuristic. An alternative is to add it as a sanitizer (#39699). This is what clang does: safestack is exposed with option `-fsanitize=safe-stack`. The options are only supported by the LLVM backend, but as with other codegen options it is visible in the main codegen option help menu. The heuristic names "basic", "strong", and "all" are hopefully sufficiently generic to be usable in other backends as well. Reviewed-by: Nikita Popov <nikic@php.net> Extra commits during review: - [address-review] make the stack-protector option unstable - [address-review] reduce detail level of stack-protector option help text - [address-review] correct grammar in comment - [address-review] use compiler flag to avoid merging functions in test - [address-review] specify min LLVM version in fortanix stack-protector test Only for Fortanix test, since this target specifically requests the `--x86-experimental-lvi-inline-asm-hardening` flag. - [address-review] specify required LLVM components in stack-protector tests - move stack protector option enum closer to other similar option enums - rustc_interface/tests: sort debug option list in tracking hash test - add an explicit `none` stack-protector option Revert "set LLVM requirements for all stack protector support test revisions" This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-11-14Don't run the codegen test when `debug_assert` is enabledScott McMurray-0/+1
2021-11-11MIRI says `reverse` is UB, so replace it with an implementation that LLVM ↵Scott McMurray-0/+26
can vectorize For small types with padding, the current implementation is UB because it does integer operations on uninit values. But LLVM has gotten smarter since I wrote the previous implementation in 2017, so remove all the manual magic and just write it in such a way that LLVM will vectorize. This code is much simpler (albeit nuanced) and has very little `unsafe`, and is actually faster to boot!
2021-11-09Specialize array cloning for Copy typesScott McMurray-0/+15
Because after PR 86041, the optimizer no longer load-merges at the LLVM IR level, which might be part of the perf loss. (I'll run perf and see if this makes a difference.) Also I added a codegen test so this hopefully won't regress in future -- it passes on stable and with my change here, but not on the 2021-11-09 nightly.
2021-11-07Add features gates for experimental asm featuresAmanieu d'Antras-1/+1
2021-10-27Auto merge of #89652 - rcvalle:rust-cfi, r=nagisabors-0/+69
Add LLVM CFI support to the Rust compiler This PR adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue #89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you, `@eddyb` and `@pcc,` for all the help!
2021-10-25Add LLVM CFI support to the Rust compilerRamon de C Valle-0/+69
This commit adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue #89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
2021-10-22Update the minimum external LLVM to 12Josh Stone-14/+0
2021-10-22Update the minimum external LLVM to 11Josh Stone-11/+0
2021-10-19Update src/test/codegen/debug-vtable.rsWesley Wiser-1/+1
Co-authored-by: r00ster <r00ster91@protonmail.com>
2021-10-19Erase late-bound regions before computing vtable debuginfo name.Michael Woerister-0/+10
2021-10-14Auto merge of #89247 - fee1-dead:const-eval-select, r=oli-obkbors-0/+17
Add `const_eval_select` intrinsic Adds an intrinsic that calls a given function when evaluated at compiler time, but generates a call to another function when called at runtime. See https://github.com/rust-lang/const-eval/issues/7 for previous discussion. r? `@oli-obk.`
2021-10-14fix codegen testDeadbeef-2/+2
2021-10-12Add const_eval_select intrinsicDeadbeef-0/+17
2021-10-11Auto merge of #89597 - michaelwoerister:improve-vtable-debuginfo, r=wesleywiserbors-21/+47
Create more accurate debuginfo for vtables. Before this PR all vtables would have the same name (`"vtable"`) in debuginfo. Now they get an unambiguous name that identifies the implementing type and the trait that is being implemented. This is only one of several possible improvements: - This PR describes vtables as arrays of `*const u8` pointers. It would nice to describe them as structs where function pointer is represented by a field with a name indicative of the method it maps to. However, this requires coming up with a naming scheme that avoids clashes between methods with the same name (which is possible if the vtable contains multiple traits). - The PR does not update the debuginfo we generate for the vtable-pointer field in a fat `dyn` pointer. Right now there does not seem to be an easy way of getting ahold of a vtable-layout without also knowing the concrete self-type of a trait object. r? `@wesleywiser`
2021-10-08Create more accurate debuginfo for vtables.Michael Woerister-21/+47
Before this commit all vtables would have the same name "vtable" in debuginfo. Now they get a name that identifies the implementing type and the trait that is being implemented.
2021-10-06fix: alloc-optimisation is only for rust llvmXimin Luo-0/+1
2021-10-01Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkovManish Goregaokar-0/+38
Add `pie` as another `relocation-model` value MCP: https://github.com/rust-lang/compiler-team/issues/461
2021-10-01Add `pie` as another `relocation-model` valueMarcel Hlopko-0/+38
2021-09-25Pin panic-in-drop=abort test to old pass managerNikita Popov-1/+8
2021-09-25Make expectation in panic-in-drop-abort.rs test more preciseNikita Popov-4/+2
Check whether a call/invoke of the function exists, but don't match a leftover function declaration. Also remove the CHECK-LABELs: In panic-in-drop=unwind mode the call will not actually be in either of those functions, so remove the restriction and look for any calls.
2021-09-20rustc_codegen_llvm: make sse4.2 imply crc32 for LLVM 14Augie Fackler-0/+16
This fixes compiling things like the `snap` crate after https://reviews.llvm.org/D105462. I added a test that verifies the additional attribute gets specified, and confirmed that I can build cargo with both LLVM 13 and 14 with this change applied.
2021-09-11Add test for -Z panic-in-drop=abortAmanieu d'Antras-0/+54
2021-09-01Rollup merge of #88350 - programmerjake:add-ppc-cr-xer-clobbers, r=AmanieuMara Bos-0/+48
add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPC Fixes #88315
2021-08-25add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPCJacob Lifshay-0/+48
Fixes #88315
2021-08-25don't generate partially-undef constsErik Desjardins-15/+39
2021-08-25use undef for uninitialized bytes in constantsErik Desjardins-2/+53
2021-08-21Auto merge of #88128 - cuviper:needs-asm-support, r=Mark-Simulacrumbors-0/+1
Add needs-asm-support to more tests These were found as test failures on s390x for RHEL and Fedora.
2021-08-17Add needs-asm-support to more testsJosh Stone-0/+1
These were found as test failures on s390x for RHEL and Fedora.
2021-08-16Remove codegen/issue-83623-SIMD-PartialEq.rsNikita Popov-46/+0
This has regressed due to https://bugs.llvm.org/show_bug.cgi?id=51211. It's pretty likely that we'll have to eat this regression for this release.
2021-08-16Update codegen tests for LLVM 13Nikita Popov-3/+3
2021-08-16Auto merge of #88032 - hyd-dev:no-mangle-method, r=petrochenkovbors-2/+3
Fix `reachable_set` for non-function items in non-library crates I unintentionally changed `reachable_set` to ignore non-function items when `!self.any_library` in https://github.com/rust-lang/rust/pull/86492, which can lead to "undefined reference" errors in non-library (`cdylib`/`staticlib`/`bin`) crates, for example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6bb2c5065a9be7e40943d0541e161b5a This PR restores the behavior of `reachable_set` for non-function items. Fixes https://github.com/rust-lang/rust/issues/88016. <details> <summary>The modified test will fail with this output without the `reachable_set` change</summary> ``` ---- [codegen] codegen/external-no-mangle-statics.rs#staticlib stdout ---- error in revision `staticlib`: verification with 'FileCheck' failed status: exit status: 1 command: "/checkout/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll" "/checkout/src/test/codegen/external-no-mangle-statics.rs" "--check-prefixes" "CHECK,NONMSVC,staticlib" stdout: ------------------------------------------ ------------------------------------------ stderr: ------------------------------------------ /checkout/src/test/codegen/external-no-mangle-statics.rs:10:11: error: CHECK: expected string not found in input // CHECK: `@A` = local_unnamed_addr constant ^ /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll:1:1: note: scanning from here ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' ^ /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll:1:6: note: possible intended match here ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' ^ Input file: /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll Check file: /checkout/src/test/codegen/external-no-mangle-statics.rs -dump-input=help explains the following input dump. Input was: <<<<<< 1: ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' check:10'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found check:10'1 ? possible intended match 2: source_filename = "external_no_mangle_statics.b50529d3-cgu.0" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4: target triple = "x86_64-unknown-linux-gnu" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: check:10'0 ~ 6: !llvm.module.flags = !{!0, !1} check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . . . >>>>>> ------------------------------------------ failures: [codegen] codegen/external-no-mangle-statics.rs#staticlib ``` </details>
2021-08-14Auto merge of #87581 - Amanieu:asm_clobber_abi, r=nagisabors-0/+35
Add support for clobber_abi to asm! This PR adds the `clobber_abi` feature that was proposed in #81092. Fixes #81092 cc `@rust-lang/wg-inline-asm` r? `@nagisa`
2021-08-15Fix `reachable_set` for non-function items in non-library crateshyd-dev-2/+3
2021-08-14Auto merge of #87324 - asquared31415:named-asm-labels, r=Amanieubors-0/+1
Lint against named asm labels This adds a deny-by-default lint to prevent the use of named labels in inline `asm!`. Without a solution to #81088 about whether the compiler should rewrite named labels or a special syntax for labels, a lint against them should prevent users from writing assembly that could break for internal compiler reasons, such as inlining or anything else that could change the number of actual inline assembly blocks emitted. This does **not** resolve the issue with rewriting labels, that still needs a decision if the compiler should do any more work to try to make them work.
2021-08-12Add support for clobber_abi to asm!Amanieu d'Antras-0/+35
2021-08-11Auto merge of #87254 - ↵bors-6/+20
rusticstuff:rustc_codegen_llvm_dont_emit_zero_sized_padding, r=eddyb LLVM codegen: Don't emit zero-sized padding for fields Currently padding is emitted before fields of a struct and at the end of the struct regardless of the ABI. Even if no padding is required zero-sized padding fields are emitted. This is not useful and - more importantly - it make it impossible to generate the exact vector types that LLVM expects for certain ARM SIMD intrinsics. This change should unblock the implementation of many ARM intrinsics using the `unadjusted` ABI, see https://github.com/rust-lang/stdarch/issues/1143#issuecomment-827404092. This is a proof of concept only because the field lookup now takes O(number of fields) time compared to O(1) before since it recalculates the mapping at every lookup. I would like to find out how big the performance impact actually is before implementing caching or restricting this behavior to the `unadjusted` ABI. cc `@SparrowLii` `@bjorn3` ([Discussion on internals](https://internals.rust-lang.org/t/feature-request-add-a-way-in-rustc-for-generating-struct-type-llvm-ir-without-paddings/15007))