-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #23489 - michaelwoerister:span-artihmetic-overflow-bug,…
… r=alexcrichton This should solve issues #23115, #23469, and #23407. As the title says, this is just a workaround. The underlying problem is that macro expansion can produce invalid spans. I've opened issue #23480 so we don't forget about that.
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![crate_type = "rlib"] | ||
// no-prefer-dynamic | ||
|
||
// compile-flags: -g | ||
|
||
#[macro_use] | ||
mod crate_with_invalid_spans_macros; | ||
|
||
pub fn exported_generic<T>(x: T, y: u32) -> (T, u32) { | ||
// Using the add1 macro will produce an invalid span, because the `y` passed | ||
// to the macro will have a span from this file, but the rest of the code | ||
// generated from the macro will have spans from the macro-defining file. | ||
// The AST node for the (1 + y) expression generated by the macro will then | ||
// take it's `lo` span bound from the `1` literal in the macro-defining file | ||
// and it's `hi` bound from `y` in this file, which should be lower than the | ||
// `lo` and even lower than the lower bound of the FileMap it is supposedly | ||
// contained in because the FileMap for this file was allocated earlier than | ||
// the FileMap of the macro-defining file. | ||
return (x, add1!(y)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
macro_rules! add1 { | ||
($e:expr) => ({ | ||
let a = 1 + $e; | ||
let b = $e + 1; | ||
a + b - 1 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:crate_with_invalid_spans.rs | ||
|
||
extern crate crate_with_invalid_spans; | ||
|
||
fn main() { | ||
// The AST of `exported_generic` stored in crate_with_invalid_spans's | ||
// metadata should contain an invalid span where span.lo > span.hi. | ||
// Let's make sure the compiler doesn't crash when encountering this. | ||
let _ = crate_with_invalid_spans::exported_generic(32u32, 7u32); | ||
} |