Commit Graph

541 Commits

Author SHA1 Message Date
codehorseman
01dbfb3eb2 resolve the conflict in compiler/rustc_session/src/parse.rs
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16 20:12:30 +08:00
Dylan DPC
13e889986d fix typos 2022-03-15 02:00:08 +01:00
Dylan DPC
1ed2a94fd2
Rollup merge of #94274 - djkoloski:unknown_unstable_lints, r=tmandry
Treat unstable lints as unknown

This change causes unstable lints to be ignored if the `unknown_lints`
lint is allowed. To achieve this, it also changes lints to apply as soon
as they are processed. Previously, lints in the same set were processed
as a batch and then all simultaneously applied.

Implementation of https://github.com/rust-lang/compiler-team/issues/469
2022-03-10 23:12:57 +01:00
Loïc BRANSTETT
6781016421 Add miri to the well known conditional compilation names and values 2022-03-09 16:58:07 +01:00
David Koloski
2677eca237 Switch the primary diagnostic to unknown_lints
This also affects the `non_exhaustive_omitted_patterns` and
`must_not_suspend` lints as they are not stable. This also changes the
diagnostic level to pull from `unknown_lints` instead of always being
allow or deny.
2022-03-08 19:07:29 +00:00
Alex Macleod
1d64b8587f Update -Z unpretty error message
Adds `thir-tree`, removes `everybody_loops`
2022-03-06 12:45:37 +00:00
Dylan DPC
afa85f0841
Rollup merge of #94362 - Urgau:check-cfg-values, r=petrochenkov
Add well known values to `--check-cfg` implementation

This pull-request adds well known values for the well known names via `--check-cfg=values()`.

[RFC 3013: Checking conditional compilation at compile time](https://rust-lang.github.io/rfcs/3013-conditional-compilation-checking.html#checking-conditional-compilation-at-compile-time) doesn't define this at all, but this seems a nice improvement.
The activation is done by a empty `values()` (new syntax) similar to `names()` except that `names(foo)` also activate well known names while `values(aa, "aa", "kk")` would not.

As stated this use a different activation logic because well known values for the well known names are not always sufficient.
In fact this is problematic for every `target_*` cfg because of non builtin targets, as the current implementation use those built-ins targets to create the list the well known values.

The implementation is straight forward, first we gather (if necessary) all the values (lazily or not) and then we apply them.

r? ```@petrochenkov```
2022-03-04 22:58:34 +01:00
Matthias Krüger
5115bdc2e2
Rollup merge of #94524 - bjorn3:remove_num_cpus, r=Mark-Simulacrum
Remove num_cpus dependency from bootstrap, build-manifest and rustc_s…

…ession

`std::threads::available_parallelism` was stabilized in rust 1.59.

r? ```````````````````````````@Mark-Simulacrum```````````````````````````
2022-03-04 17:31:05 +01:00
Loïc BRANSTETT
4aa92aff05 Add well known values to --check-cfg implementation 2022-03-04 11:15:38 +01:00
Dylan DPC
c1585a17a3
Rollup merge of #93913 - bjorn3:remove_everybody_loops, r=jackh726
Remove the everybody loops pass

It isn't used anymore by rustdoc.

Split out of https://github.com/rust-lang/rust/pull/92895. There has been some previous discussion there.
2022-03-04 02:06:38 +01:00
bors
10913c0001 Auto merge of #87835 - xFrednet:rfc-2383-expect-attribute-with-ids, r=wesleywiser
Implementation of the `expect` attribute (RFC 2383)

This is an implementation of the `expect` attribute as described in [RFC-2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html). The attribute allows the suppression of lint message by expecting them. Unfulfilled lint expectations (meaning no expected lint was caught) will emit the `unfulfilled_lint_expectations` lint at the `expect` attribute.

### Example
#### input
```rs
// required feature flag
#![feature(lint_reasons)]

#[expect(unused_mut)] // Will warn about an unfulfilled expectation
#[expect(unused_variables)] // Will be fulfilled by x
fn main() {
    let x = 0;
}
```

#### output

```txt
warning: this lint expectation is unfulfilled
  --> $DIR/trigger_lint.rs:3:1
   |
LL | #[expect(unused_mut)] // Will warn about an unfulfilled expectation
   |          ^^^^^^^^^^
   |
   = note: `#[warn(unfulfilled_lint_expectations)]` on by default
```

### Implementation

This implementation introduces `Expect` as a new lint level for diagnostics, which have been expected. All lint expectations marked via the `expect` attribute are collected in the [`LintLevelsBuilder`] and assigned an ID that is stored in the new lint level. The `LintLevelsBuilder` stores all found expectations and the data needed to emit the `unfulfilled_lint_expectations` in the [`LintLevelsMap`] which is the result of the [`lint_levels()`] query.

The [`rustc_errors::HandlerInner`] is the central error handler in rustc and handles the emission of all diagnostics. Lint message with the level `Expect` are suppressed during this emission, while the expectation ID is stored in a set which marks them as fulfilled. The last step is then so simply check if all expectations collected by the [`LintLevelsBuilder`] in the [`LintLevelsMap`] have been marked as fulfilled in the [`rustc_errors::HandlerInner`]. Otherwise, a new lint message will be emitted.

The implementation of the `LintExpectationId` required some special handling to make it stable between sessions. Lints can be emitted during [`EarlyLintPass`]es. At this stage, it's not possible to create a stable identifier. The level instead stores an unstable identifier, which is later converted to a stable `LintExpectationId`.

### Followup TO-DOs
All open TO-DOs have been marked with `FIXME` comments in the code. This is the combined list of them:

* [ ] The current implementation doesn't cover cases where the `unfulfilled_lint_expectations` lint is actually expected by another `expect` attribute.
   * This should be easily possible, but I wanted to get some feedback before putting more work into this.
   * This could also be done in a new PR to not add to much more code to this one
* [ ] Update unstable documentation to reflect this change.
* [ ] Update unstable expectation ids in [`HandlerInner::stashed_diagnostics`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.HandlerInner.html#structfield.stashed_diagnostics)

### Open questions
I also have a few open questions where I would like to get feedback on:
1. The RFC discussion included a suggestion to change the `expect` attribute to something else. (Initiated by `@Ixrec` [here](https://github.com/rust-lang/rfcs/pull/2383#issuecomment-378424091), suggestion from `@scottmcm` to use `#[should_lint(...)]` [here](https://github.com/rust-lang/rfcs/pull/2383#issuecomment-378648877)). No real conclusion was drawn on that point from my understanding. Is this still open for discussion, or was this discarded with the merge of the RFC?
2. How should the expect attribute deal with the new `force-warn` lint level?

---

This approach was inspired by a discussion with `@LeSeulArtichaut.`

RFC tracking issue: #54503

Mentoring/Implementation issue: #85549

[`LintLevelsBuilder`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/levels/struct.LintLevelsBuilder.html
[`LintLevelsMap`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/struct.LintLevelMap.html
[`lint_levels()`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.lint_levels
[`rustc_errors::HandlerInner`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.HandlerInner.html
[`EarlyLintPass`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
2022-03-03 18:59:32 +00:00
bjorn3
2f84484aac Remove the everybody loops pass
It isn't used anymore by rustdoc
2022-03-03 18:23:09 +01:00
Amanieu d'Antras
aa36237e16 Add -Z oom={panic,abort} command-line option 2022-03-03 12:58:38 +00:00
Loïc BRANSTETT
50e61a1a66 Add support for values() with --check-cfg 2022-03-03 12:00:28 +01:00
xFrednet
2ca9037b61
Set LintExpectationId in level and collect fulfilled ones (RFC-2383)
* Collect lint expectations and set expectation ID in level (RFC-2383)
* Collect IDs of fulfilled lint expectations from diagnostics (RFC 2383)
2022-03-02 17:46:07 +01:00
xFrednet
9fef3d9e0a
Added Expect lint level and attribute (RFC-2383)
* Also added the `LintExpectationId` which will be used in future commits
2022-03-02 17:46:05 +01:00
mark
e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
bjorn3
2d854f9c34 Remove num_cpus dependency from bootstrap, build-manifest and rustc_session 2022-03-02 15:39:04 +01:00
bors
761e888485 Auto merge of #93516 - nagisa:branch-protection, r=cjgillot
No branch protection metadata unless enabled

Even if we emit metadata disabling branch protection, this metadata may
conflict with other modules (e.g. during LTO) that have different branch
protection metadata set.

This is an unstable flag and feature, so ideally the flag not being
specified should act as if the feature wasn't implemented in the first
place.

Additionally this PR also ensures we emit an error if
`-Zbranch-protection` is set on targets other than the supported
aarch64. For now the error is being output from codegen, but ideally it
should be moved to earlier in the pipeline before stabilization.
2022-02-26 21:53:03 +00:00
Mark Rousskov
22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
bors
ece55d416e Auto merge of #94130 - erikdesjardins:partially, r=nikic
Use undef for (some) partially-uninit constants

There needs to be some limit to avoid perf regressions on large arrays
with undef in each element (see comment in the code).

Fixes: #84565
Original PR: #83698

Depends on LLVM 14: #93577
2022-02-25 05:44:33 +00:00
bors
d4de1f230c Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".

That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
  * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
  * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
  * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
    (though note that this isn't a real guarantee until after completing the work on
     #69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
  * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`

This PR is a companion to other ongoing work, namely:
* #69426
  and it's ongoing implementation:
  #93222
  the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
  would make the choices of API changes (esp. naming) in this PR fit better overall

In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
  * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
  * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
  * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
  * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
  * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
  we have to make `.emit()` idempotent wrt the guarantees it returns
  * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
  * the APIs were already mostly identical, allowing for low-effort porting to this new setup
  * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
  * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
  * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)

This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.

r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-25 00:46:04 +00:00
Dylan DPC
000e38d9cb
Rollup merge of #94175 - Urgau:check-cfg-improvements, r=petrochenkov
Improve `--check-cfg` implementation

This pull-request is a mix of improvements regarding the `--check-cfg` implementation:

- Simpler internal representation (usage of `Option` instead of separate bool)
- Add --check-cfg to the unstable book (based on the RFC)
- Improved diagnostics:
    * List possible values when the value is unexpected
    * Suggest if possible a name or value that is similar
- Add more tests (well known names, mix of combinations, ...)

r? ```@petrochenkov```
2022-02-24 21:42:13 +01:00
Loïc BRANSTETT
8d3de56da1 Continue improvements on the --check-cfg implementation
- Test the combinations of --check-cfg with partial values() and --cfg
- Test that we detect unexpected value when none are expected
2022-02-23 13:22:23 +01:00
Eduard-Mihai Burtescu
b7e95dee65 rustc_errors: let DiagnosticBuilder::emit return a "guarantee of emission". 2022-02-23 06:38:52 +00:00
Eduard-Mihai Burtescu
d4fc5ae25c rustc_errors: handle force_warn only through DiagnosticId::Lint. 2022-02-23 05:38:24 +00:00
Eduard-Mihai Burtescu
02ff9e0aef Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic. 2022-02-23 05:38:19 +00:00
Loïc BRANSTETT
da896d35f4 Improve CheckCfg internal representation 2022-02-22 22:41:49 +01:00
Matthias Krüger
f2d6770f77
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-20 00:37:34 +01:00
est31
2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
Erik Desjardins
c2e84fa5fc reduce default uninit_const_chunk_threshold to 16 (from 256) 2022-02-19 10:36:29 -05:00
Simonas Kazlauskas
b995dc944c No branch protection metadata unless enabled
Even if we emit metadata disabling branch protection, this metadata may
conflict with other modules (e.g. during LTO) that have different branch
protection metadata set.

This is an unstable flag and feature, so ideally the flag not being
specified should act as if the feature wasn't implemented in the first
place.

Additionally this PR also ensures we emit an error if
`-Zbranch-protection` is set on targets other than the supported
aarch64. For now the error is being output from codegen, but ideally it
should be moved to earlier in the pipeline before stabilization.
2022-02-19 17:31:40 +02:00
Erik Desjardins
d5769e9843 switch to limiting the number of init/uninit chunks 2022-02-19 01:29:17 -05:00
Matthias Krüger
576afec73a
Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov
Implement --check-cfg option (RFC 3013), take 2

This pull-request implement RFC 3013: Checking conditional compilation at compile time (https://github.com/rust-lang/rfcs/pull/3013) and is based on the previous attempt https://github.com/rust-lang/rust/pull/89346 by `@mwkmwkmwk` that was closed due to inactivity.

I have address all the review comments from the previous attempt and added some more tests.

cc https://github.com/rust-lang/rust/issues/82450
r? `@petrochenkov`
2022-02-18 23:23:10 +01:00
Matthias Krüger
0bb72a2c66
Rollup merge of #91675 - ivanloz:memtagsan, r=nagisa
Add MemTagSanitizer Support

Add support for the LLVM [MemTagSanitizer](https://llvm.org/docs/MemTagSanitizer.html).

On hardware which supports it (see caveats below), the MemTagSanitizer can catch bugs similar to AddressSanitizer and HardwareAddressSanitizer, but with lower overhead.

On a tag mismatch, a SIGSEGV is signaled with code SEGV_MTESERR / SEGV_MTEAERR.

# Usage

`-Zsanitizer=memtag -C target-feature="+mte"`

# Comments/Caveats

* MemTagSanitizer is only supported on AArch64 targets with hardware support
* Requires `-C target-feature="+mte"`
* LLVM MemTagSanitizer currently only performs stack tagging.

# TODO

* Tests
* Example
2022-02-18 23:23:03 +01:00
Erik Desjardins
b7e5597491 Use undef for partially-uninit constants up to 1024 bytes
There needs to be some limit to avoid perf regressions on large arrays
with undef in each element (see comment in the code).
2022-02-18 15:57:10 -05:00
Ivan Lozano
568aeda9e9 MemTagSanitizer Support
Adds support for the LLVM MemTagSanitizer.
2022-02-16 09:39:03 -05:00
Loïc BRANSTETT
3a73ca587b Implement --check-cfg option (RFC 3013)
Co-authored-by: Urgau <lolo.branstett@numericable.fr>
Co-authored-by: Marcelina Kościelnicka <mwk@0x04.net>
2022-02-16 13:03:12 +01:00
Andrew Brown
8d6c973c7f Add support for control-flow protection
This change adds a flag for configuring control-flow protection in the
LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with
options `none|branch|return|full`. This convention is followed for
`rustc`, though as a codegen option: `rustc -Z
cf-protection=<none|branch|return|full>`.

Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2022-02-14 08:31:24 -08:00
bjorn3
55ceed81fe Remove the alt_std_name option
This option introduced in #15820 allows a custom crate to be imported in
the place of std, but with the name std. I don't think there is any
value to this. At most it is confusing users of a driver that uses this option. There are no users of
this option on github. If anyone still needs it, they can emulate it
injecting #![no_core] in addition to their own prelude.
2022-02-11 20:28:38 +01:00
bors
9747ee4755 Auto merge of #93724 - Mark-Simulacrum:drop-query-stats, r=michaelwoerister
Delete -Zquery-stats infrastructure

These statistics are computable from the self-profile data and/or ad-hoc collectable as needed, and in the meantime contribute to rustc bootstrap times -- locally, this PR shaves ~2.5% from rustc_query_impl builds in instruction counts.

If this does lose some functionality we want to keep, I think we should migrate it to self-profile (or a similar interface) rather than this ad-hoc reporting.
2022-02-09 15:53:10 +00:00
Tomasz Miąsko
29185844c4 Add a flag enabling drop range tracking in generators 2022-02-07 12:27:09 -08:00
Mark Rousskov
257839bd88 Delete query stats
These statistics are computable from the self-profile data and/or ad-hoc
collectable as needed, and in the meantime contribute to rustc bootstrap times.
2022-02-06 21:35:00 -05:00
Matthias Krüger
9b7f1f5649
Rollup merge of #93608 - nnethercote:speed-up-find_library_crate, r=petrochenkov
Clean up `find_library_crate`

Some clean-ups.

r? `@petrochenkov`
2022-02-04 18:42:16 +01:00
Matthias Krüger
2fe9a32ed2
Rollup merge of #90132 - joshtriplett:stabilize-instrument-coverage, r=wesleywiser
Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: https://github.com/rust-lang/rust/issues/79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on https://github.com/rust-lang/rust/pull/90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](https://github.com/rust-lang/rust/issues/79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at https://github.com/rust-lang/compiler-team/issues/278 . Based on that, `@pnkfelix` suggested that this needed a stabilization PR and a compiler-team FCP.
2022-02-04 18:42:13 +01:00
Nicholas Nethercote
0ba47f3216 Make SearchPathFile::file_name_str non-optional.
Currently, it can be `None` if the conversion from `OsString` fails, in
which case all searches will skip over the `SearchPathFile`.

The commit changes things so that the `SearchPathFile` just doesn't get
created in the first place. Same behaviour, but slightly simpler code.
2022-02-02 13:16:25 +11:00
Nicholas Nethercote
89b61ea09f Inline and remove FileSearch::search.
It has only a single callsite, and having all the code in one place will
make it possible to optimize the search.
2022-02-02 09:06:34 +11:00
Nicholas Nethercote
47b5d95db8 Remove FileMatch.
It's returned from `FileSearch::search` but it's only used to print some
debug info.
2022-02-02 09:06:34 +11:00
Nicholas Nethercote
f916f3a36b Remove rlib special-casing in FileSearch::search.
This code and comment appear to be out of date.
`CrateLocator::find_library_crate` is the only caller of this function
and it handles rlib vs dylib overlap itself (see
`CrateLocator::extract_lib`) after inspecting all the files present, so
it doesn't need to see them in any particular order.
2022-02-02 09:06:34 +11:00
Daniel Frampton
e22729b464 Add missing | between print options 2022-02-01 12:40:01 -08:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Matthias Krüger
a1645e5b57
Rollup merge of #93229 - mark-i-m:noquiet, r=eddyb
Remove DiagnosticBuilder.quiet

r? `@eddyb`

cc https://github.com/rust-lang/rust/issues/69426 `@GuillaumeGomez` `@Manishearth`
2022-01-23 20:13:07 +01:00
mark
cf382de0cc Remove DiagnosticBuilder.quiet 2022-01-23 00:11:13 -06:00
Vadim Petrochenkov
29d623528d Gate l4-bender linker flavor 2022-01-21 16:51:10 +01:00
Matthias Krüger
02379e917b
Rollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pnkfelix
Stabilize `-Z print-link-args` as `--print link-args`

We have stable options for adding linker arguments; we should have a
stable option to help debug linker arguments.

Add documentation for the new option. In the documentation, make it clear that
the *exact* format of the output is not a stable guarantee.
2022-01-20 17:10:32 +01:00
Matthias Krüger
dd621a4c5c
Rollup merge of #90782 - ricobbe:binutils-dlltool, r=michaelwoerister
Implement raw-dylib support for windows-gnu

Add support for `#[link(kind = "raw-dylib")]` on windows-gnu targets.  Work around binutils's linker's inability to read import libraries produced by LLVM by calling out to the binutils `dlltool` utility to create an import library from a temporary .DEF file; this approach is effectively a slightly refined version of `@mati865's` earlier attempt at this strategy in PR #88801.  (In particular, this attempt at this strategy adds support for `#[link_ordinal(...)]` as well.)

In support of #58713.
2022-01-18 22:00:42 +01:00
Richard Cobbe
0cf7fd1208 Call out to binutils' dlltool for raw-dylib on windows-gnu platforms. 2022-01-12 10:25:35 -08:00
Josh Triplett
cd626fec2b Stabilize -Z print-link-args as --print link-args
We have stable options for adding linker arguments; we should have a
stable option to help debug linker arguments.
2022-01-09 13:22:50 -08:00
David Wood
08ed338f56 sess/cg: re-introduce split dwarf kind
In #79570, `-Z split-dwarf-kind={none,single,split}` was replaced by `-C
split-debuginfo={off,packed,unpacked}`. `-C split-debuginfo`'s packed
and unpacked aren't exact parallels to single and split, respectively.

On Unix, `-C split-debuginfo=packed` will put debuginfo into object
files and package debuginfo into a DWARF package file (`.dwp`) and
`-C split-debuginfo=unpacked` will put debuginfo into dwarf object files
and won't package it.

In the initial implementation of Split DWARF, split mode wrote sections
which did not require relocation into a DWARF object (`.dwo`) file which
was ignored by the linker and then packaged those DWARF objects into
DWARF packages (`.dwp`). In single mode, sections which did not require
relocation were written into object files but ignored by the linker and
were not packaged. However, both split and single modes could be
packaged or not, the primary difference in behaviour was where the
debuginfo sections that did not require link-time relocation were
written (in a DWARF object or the object file).

This commit re-introduces a `-Z split-dwarf-kind` flag, which can be
used to pick between split and single modes when `-C split-debuginfo` is
used to enable Split DWARF (either packed or unpacked).

Signed-off-by: David Wood <david.wood@huawei.com>
2022-01-06 09:32:42 +00:00
Josh Triplett
6593fcd824 Require -Zunstable-options for -C instrument-coverage=except-* options
These options primarily exist to work around bugs, and those bugs have
largely been fixed. Avoid stabilizing them, so that we don't have to
support them indefinitely.
2022-01-01 16:15:36 -08:00
Josh Triplett
34106f8935 Stabilize -Z instrument-coverage as -C instrument-coverage
Continue supporting -Z instrument-coverage for compatibility for now,
but show a deprecation warning for it.

Update uses and documentation to use the -C option.

Move the documentation from the unstable book to stable rustc
documentation.
2022-01-01 15:57:35 -08:00
Josh Triplett
ff94b3b12b Update references to -Z symbol-mangling-version to use -C
Replace `-Z symbol-mangling-version=v0` with `-C symbol-mangling-version=v0`.

Replace `-Z symbol-mangling-version=legacy` with
`-Z unstable-options -C symbol-mangling-version=legacy`.
2022-01-01 15:53:11 -08:00
Josh Triplett
bbf4b6699e Stabilize -Z symbol-mangling-version as -C symbol-mangling-version
This allows selecting `v0` symbol-mangling without an unstable option.
Selecting `legacy` still requires -Z unstable-options.

Continue supporting -Z symbol-mangling-version for compatibility for
now, but show a deprecation warning for it.
2022-01-01 15:51:02 -08:00
bors
984a6bf9c1 Auto merge of #92175 - Aaron1011:fix-missing-source-file, r=cjgillot
Import `SourceFile`s from crate before decoding foreign `Span`

Fixes #92163
Fixes #92014

When writing to the incremental cache, we encode all `Span`s
we encounter, regardless of whether or not their `SourceFile`
comes from the local crate, or from a foreign crate.

When we decode a `Span`, we use the `StableSourceFileId` we encoded
to locate the matching `SourceFile` in the current session. If this
id corresponds to a `SourceFile` from another crate, then we need to
have already imported that `SourceFile` into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a `Span` from a transitive dependency
without having ever imported the `SourceFile`s from that crate, leading
to an ICE.

This PR fixes the issue by enconding the `SourceFile`'s `CrateNum`
when we encode a `Span`. During decoding, we call `imported_source_files()`
when we encounter a foreign `CrateNum`, which ensure that all
`SourceFile`s from that crate are imported into the current session.
2021-12-31 16:38:23 +00:00
bors
d331cb710f Auto merge of #88354 - Jmc18134:hint-space-pauth-opt, r=nagisa
Add codegen option for branch protection and pointer authentication on AArch64

The branch-protection codegen option enables the use of hint-space pointer
authentication code for AArch64 targets.
2021-12-29 22:35:11 +00:00
Aaron Hill
d9220924dc
Import SourceFiles from crate before decoding foreign Span
Fixes #92163
Fixes #92014

When writing to the incremental cache, we encode all `Span`s
we encounter, regardless of whether or not their `SourceFile`
comes from the local crate, or from a foreign crate.

When we decode a `Span`, we use the `StableSourceFileId` we encoded
to locate the matching `SourceFile` in the current session. If this
id corresponds to a `SourceFile` from another crate, then we need to
have already imported that `SourceFile` into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a `Span` from a transitive dependency
without having ever imported the `SourceFile`s from that crate, leading
to an ICE.

This PR fixes the issue by calling `imported_source_files()`
when we encounter a `SourceFile` with a foreign `CrateNum`.
This ensures that all `SourceFile`s from that crate are imported
into the current session.
2021-12-23 12:56:12 -05:00
bors
41c3017c82 Auto merge of #92099 - matthiaskrgr:rollup-4gwv67m, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91141 (Revert "Temporarily rename int_roundings functions to avoid conflicts")
 - #91984 (Remove `in_band_lifetimes` from `rustc_middle`)
 - #92028 (Sync portable-simd to fix libcore build for AVX-512 enabled targets)
 - #92042 (Enable `#[thread_local]` for all windows-msvc targets)
 - #92071 (Update example code for Vec::splice to change the length)
 - #92077 (rustdoc: Remove unused `collapsed` field)
 - #92081 (rustdoc: Remove unnecessary `need_backline` function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-19 12:36:56 +00:00
Matthias Krüger
4dbe966fdd
Rollup merge of #92042 - ChrisDenton:msvc-static-tls, r=nagisa
Enable `#[thread_local]` for all windows-msvc targets

As it stands, `#[thread_local]` is enabled haphazardly for msvc. It seems all 64-bit targets have it enabled, but not 32-bit targets unless they're also UWP targets (perhaps because UWP was added more recently?). So this PR simply enables it for 32-bit targets as well. I can't think of a reason not to and I've confirmed by running tests locally which pass.

See also #91659
2021-12-19 10:45:53 +01:00
bors
a41a6925ba Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
Matthias Krüger
6b62bf3814
Rollup merge of #91932 - Kixiron:randomize-seed, r=nagisa
Add user seed to `-Z randomize-layout`

Allows users of -`Z randomize-layout` to provide `-Z layout-seed=<seed>` in order to further randomizing type layout randomization. Extension of [compiler-team/#457](https://github.com/rust-lang/compiler-team/issues/457), allows users to change struct layouts without changing code and hoping that item path hashes change, aiding in detecting layout errors
2021-12-19 00:38:41 +01:00
Chris Denton
391332c5d9
Rename has_elf_tls to has_thread_local 2021-12-17 20:56:38 +00:00
Nicholas Nethercote
056d48a2c9 Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Chase Wilson
2b46c7c906
Added -Z layout_seed for allowing user-defined randomization seeds 2021-12-14 12:48:41 -06:00
Matthias Krüger
97e844a032 fix clippy::single_char_pattern perf findings 2021-12-14 12:40:28 +01:00
est31
15de4cbc4b Remove redundant [..]s 2021-12-09 00:01:29 +01:00
bors
772d51f887 Auto merge of #91555 - matthiaskrgr:rollup-pq0iaq7, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #90529 (Skip reborrows in AbstractConstBuilder)
 - #91437 (Pretty print empty blocks as {})
 - #91450 (Don't suggest types whose inner type is erroneous)
 - #91535 (Stabilize `-Z emit-future-incompat` as `--json future-incompat`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-05 15:33:44 +00:00
Matthias Krüger
068b30420a
Rollup merge of #91535 - Aaron1011:stabilize-future-incompat, r=nagisa
Stabilize `-Z emit-future-incompat` as `--json future-incompat`

The FCP was completed in https://github.com/rust-lang/rust/issues/71249
2021-12-05 15:04:22 +01:00
bors
1597728ef5 Auto merge of #88611 - m-ou-se:array-into-iter-new-deprecate, r=joshtriplett
Deprecate array::IntoIter::new.
2021-12-05 12:53:01 +00:00
Aaron Hill
63523e4d1c
Stabilize -Z emit-future-incompat as --json future-incompat 2021-12-04 14:34:20 -05:00
Mara Bos
1acb44f03c Use IntoIterator for array impl everywhere. 2021-12-04 19:40:33 +01:00
Dylan MacKenzie
a0de6346de Move instrument coverage config getters to Options 2021-12-02 17:12:59 -08:00
Dylan MacKenzie
386b1c5f57 Move mir_opt_level getter into Options 2021-12-02 17:12:58 -08:00
Jamie Cunliffe
984ca4689d Review comments
- 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-01 15:56:59 +00:00
James McGregor
837cc1687f Add codegen option for branch protection and pointer authentication on AArch64
The branch-protection codegen option enables the use of hint-space pointer
authentication code for AArch64 targets
2021-12-01 12:24:30 +00:00
Tomasz Miąsko
e74e39a699 Accumulate all values of -C remark option
When `-C remark=...` option is specified multiple times,
accumulate all values instead of using only the last one.
2021-11-29 09:12:01 +01:00
Matthias Krüger
984e644432
Rollup merge of #91185 - camelid:rm-force-overflow-checks, r=wesleywiser
Remove `-Z force-overflow-checks`

It was replaced several years ago by the stable option `-C overflow-checks`.
The goal was to delete the `-Z` flag once users had migrated [1].
Now that it's been several years, it makes sense to delete the old flag.

See also the discussion on Zulip [2].

[1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097
[2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224

r? ```@wesleywiser```
cc ```@RalfJung```
2021-11-25 15:05:40 +01:00
bors
23a436606b Auto merge of #88781 - estebank:emoji-idents, r=oli-obk
Tokenize emoji as if they were valid identifiers

In the lexer, consider emojis to be valid identifiers and reject
them later to avoid knock down parse errors.

Partially address #86102.
2021-11-25 08:16:08 +00:00
Noah Lev
f0b990a8f9 Remove -Z force-overflow-checks
It was replaced several years ago by the stable option `-C
overflow-checks`. The goal was to delete the `-Z` flag once users had
migrated [1]. Now that it's been several years, it makes sense to delete
the old flag.

See also the discussion on Zulip [2].

[1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097
[2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224
2021-11-24 10:19:23 -08:00
Esteban Kuber
d68add9ecc review comment: plural of emoji is emoji 2021-11-23 20:36:19 +00:00
Esteban Kuber
5a68abb094 Tokenize emoji as if they were valid indentifiers
In the lexer, consider emojis to be valid identifiers and reject
them later to avoid knock down parse errors.
2021-11-23 20:35:07 +00:00
Matthias Krüger
e52e3a4bb3
Rollup merge of #91148 - jhpratt:use-default-enum, r=petrochenkov
Use `derive_default_enum` in the compiler

Let's get this feature some real-world love.

``@rustbot`` label: +C-cleanup +S-waiting-on-review
2021-11-23 19:28:11 +01:00
Jacob Pratt
7b103e7dd2
Use derive_default_enum in the compiler 2021-11-22 20:17:53 -05:00
Benjamin A. Bjørnseth
bb9dee95ed add rustc option for using LLVM stack smash protection
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-22 20:06:22 +01:00
bors
ce3f3a5ffa Auto merge of #90329 - nbdd0121:typeck, r=nagisa
Try all stable method candidates first before trying unstable ones

Currently we try methods in this order in each step:
* Stable by value
* Unstable by value
* Stable autoref
* Unstable autoref
* ...

This PR changes it to first try pick methods without any unstable candidates, and if none is found, try again to pick unstable ones.

Fix #90320
CC #88971, hopefully would allow us to rename the "unstable_*" methods for integer impls back.

`@rustbot` label T-compiler T-libs-api
2021-11-19 03:00:46 +00:00
Yuki Okushi
728b3f2356
Rollup merge of #90386 - pierwill:assert-incr-state-85864, r=Aaron1011
Add `-Zassert-incr-state` to assert state of incremental cache

Closes #85864.
2021-11-19 02:22:54 +09:00
Josh Triplett
e35b7bbdf8 Stabilize -Z strip as -C strip
Leave -Z strip available temporarily as an alias, to avoid breaking
cargo until cargo transitions to using -C strip. (If the user passes
both, the -C version wins.)
2021-11-15 10:21:02 +01:00
Josh Triplett
c4884bbec7 Support having -Z and -C options with the same name
Tweak the `options!` macro to allow for -Z and -C options with the same
name without generating conflicting internal parsing functions.

Split out of the commit stabilizing -Z strip as -C strip.
2021-11-15 10:18:30 +01:00
Gary Guo
6a207f23eb Try all stable candidates first before trying unstable ones 2021-11-15 02:14:54 +00:00
pierwill
1642fdfea0 Add -Zassert-incr-state to assert state of incremental cache 2021-11-12 13:41:46 -06:00
bors
9dbbbb12c0 Auto merge of #83846 - torhovland:issue-10971, r=davidtwco
Added the --temps-dir option

Fixes #10971.

The new `--temps-dir` option puts intermediate files in a user-specified directory. This provides a fix for the issue where parallel invocations of rustc would overwrite each other's intermediate files.

No files are kept in the intermediate directory unless `-C save-temps=yes`.

If additional files are specifically requested using `--emit asm,llvm-bc,llvm-ir,obj,metadata,link,dep-info,mir`, these will be put in the output directory rather than the intermediate directory.

This is a backward-compatible change, i.e. if `--temps-dir` is not specified, the behavior is the same as before.
2021-11-11 02:52:32 +00:00