mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Make snegate / unegate overflow handling consistent with other builtins. (#4744)
Make `int.snegate` ignore the signedness of its operand and unconditionally check for signed overflow like all the other `int.s*` builtins do. Fix the prelude implementation of unary `-` for `Core.UInt` to use `int.unegate` instead of `int.snegate`. Fix the test for unsigned negate to actually test negating unsigned integers, and add some tests that unary `-` also works.
This commit is contained in:
@@ -783,7 +783,7 @@ static auto PerformBuiltinUnaryIntOp(Context& context, SemIRLoc loc,
|
||||
|
||||
switch (builtin_kind) {
|
||||
case SemIR::BuiltinFunctionKind::IntSNegate:
|
||||
if (is_signed && op_val.isMinSignedValue()) {
|
||||
if (op_val.isMinSignedValue()) {
|
||||
CARBON_DIAGNOSTIC(CompileTimeIntegerNegateOverflow, Error,
|
||||
"integer overflow in negation of {0}", TypedInt);
|
||||
context.emitter().Emit(loc, CompileTimeIntegerNegateOverflow,
|
||||
|
||||
Reference in New Issue
Block a user