Skip to content

ICE in expand_message, at rust/rust-diagnostics.cc #4252

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use
fn main() {
    let _ = [(); {
        let mut n = 113383;
        while n != 0 {
            n = if if {
                let mut n = 113383;
                while n != 0 {
                    n = if if n % 2 == 0 { n / 2 } else { 3 * n + 1 } % 2 == 0 {
                        n / 2
                    } else {
                        3 * n + 1
                    };
                }
                n
            } == 0
            {
                n / 2
            } else {
                3 * n + 1
            } % 2
                == 0
            {
                n / 2
            } else {
                3 * n + 1
            };
        }
        n
    }];
}

original:

fn main() {
    // Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
    // The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
    let _ = [(); {
        let mut n = 113383; // #20 in https://oeis.org/A006884
        while n != 0 {
            n = if if {
        let mut n = 113383; // #20 in https://oeis.org/A006884
        while n != 0 {
            n = if if n % 2 == 0 { n/2 } else { 3*n + 1 } % 2 == 0 { n/2 } else { 3*n + 1 };
            //~^ ERROR evaluation of constant value failed
        }
        n
    } == 0 { n/2 } else { 3*n + 1 } % 2 == 0 { n/2 } else { 3*n + 1 };
            //~^ ERROR evaluation of constant value failed
        }
        n
    }];
}

Version information:

dbf131a

Possibly related line of code:

int nwr = vasprintf (&mbuf, expanded_fmt.c_str (), ap);
if (nwr == -1)
{
// memory allocation failed
rust_be_error_at (UNKNOWN_LOCATION,
"memory allocation failed in vasprintf");
rust_assert (0);
}
std::string rval = std::string (mbuf);
free (mbuf);
return rval;
}

Command:
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use

Program output

crab1: error: memory allocation failed in vasprintf
crab1: internal compiler error: in expand_message, at rust/rust-diagnostics.cc:131
0x3073c69 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:787
0xc36943 fancy_abort(char const*, int, char const*)
	../../gcc/diagnostics/context.cc:1806
0xcab899 expand_message
	../../gcc/rust/rust-diagnostics.cc:131
0xcab899 expand_message
	../../gcc/rust/rust-diagnostics.cc:121
0xcac3e0 rust_error_at(unsigned long, char const*, ...)
	../../gcc/rust/rust-diagnostics.cc:198
0x1169979 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:1970
0x1169356 eval_statement_list
	../../gcc/rust/backend/rust-constexpr.cc:4877
0x1169356 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2261
0x11687bf eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2265
0x1169356 eval_statement_list
	../../gcc/rust/backend/rust-constexpr.cc:4877
0x1169356 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2261
0x11687bf eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2265
0x1168a57 eval_loop_expr
	../../gcc/rust/backend/rust-constexpr.cc:5113
0x1168a57 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2395
0x1169356 eval_statement_list
	../../gcc/rust/backend/rust-constexpr.cc:4877
0x1169356 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2261
0x11687bf eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2265
0x1169356 eval_statement_list
	../../gcc/rust/backend/rust-constexpr.cc:4877
0x1169356 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2261
0x11687bf eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2265
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions