- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Don't perform invalid checks in codegen_attrs
          #105605
        
          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
Conversation
| ☔ The latest upstream changes (presumably #105667) made this pull request unmergeable. Please resolve the merge conflicts. | 
a8f3ba1    to
    31dafc0      
    Compare
  
    collectcodegen_attrs
      Some attributes are only valid on function items. When checking these attributes, codegen_attrs previously sometimes called `fn_sig` on the item they were attached to without first ensuring that the item was a function. This led to an ICE (rust-lang#105594), since `fn_sig` can only be called on functions. After this change, we skip calling `fn_sig` if the item the attribute is attached to must be a function but invalidly isn't, because `check_attr` will reject such cases without codegen_attrs's intervention.
31dafc0    to
    fc3bcf1      
    Compare
  
    74018c2    to
    47b6426      
    Compare
  
    | There's a bit of a backwards compatibility hazard here, in that  | 
| 
 The assertion  @bors r+ | 
| ⌛ Testing commit 47b6426 with merge c29f2720036ecf11a7b77c6e666da43436e59cf1... | 
| 💔 Test failed - checks-actions | 
| @bors retry | 
| ☀️ Test successful - checks-actions | 
| Finished benchmarking commit (f206533): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 | 
…r=cjgillot Don't perform invalid checks in `codegen_attrs` The attributes `#[track_caller]` and `#[cmse_nonsecure_entry]` are only valid on functions. When validating one of these attributes, codegen_attrs previously called `fn_sig`, [which can only be used on functions](rust-lang#105201), on the item the attribute was attached to, assuming that the item was a function without checking. This led to [ICEs in situations where the attribute was incorrectly used on non-functions](rust-lang#105594). With this change, we skip calling `fn_sig` if the item the attribute is attached to must be a function but isn't, because `check_attr` will reject such cases without codegen_attrs's intervention. As a side note, some of the attributes in codegen_attrs are only valid on functions, but that property isn't actually checked. I'm planning to fix that in a follow up PR since it's a behavior change that will need to be validated rather than an obvious bugfix. Thankfully, all the attributes like that I've found so far are unstable. Fixes rust-lang#105594. r? `@cjgillot`
The attributes
#[track_caller]and#[cmse_nonsecure_entry]are only valid on functions. When validating one of these attributes, codegen_attrs previously calledfn_sig, which can only be used on functions, on the item the attribute was attached to, assuming that the item was a function without checking. This led to ICEs in situations where the attribute was incorrectly used on non-functions.With this change, we skip calling
fn_sigif the item the attribute is attached to must be a function but isn't, becausecheck_attrwill reject such cases without codegen_attrs's intervention.As a side note, some of the attributes in codegen_attrs are only valid on functions, but that property isn't actually checked. I'm planning to fix that in a follow up PR since it's a behavior change that will need to be validated rather than an obvious bugfix. Thankfully, all the attributes like that I've found so far are unstable.
Fixes #105594.
r? @cjgillot