hax0kartik wrote:

> > In these particular case(s), we should use INTXX_MAX instead.
> 
> @hax0kartik Could you please explain why we should use INTXX_MAX and not just 
> skip the negation part for this case like in 
> [clang::Interp::Integral::neg](https://github.com/llvm/llvm-project/blob/ec399ef172338e42642c8fe894dc753a2a34b98d/clang/lib/AST/ByteCode/Integral.h#L265)?
> 
> Thank you in advance!

```C++
if (RHS.isNegative()) {
    // During constant-folding, a negative shift is an opposite shift. Such a
    // shift is not a constant expression.
    const SourceInfo &Loc = S.Current->getSource(OpPC);
    S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
    if (!S.noteUndefinedBehavior())
      return false;

    RHS = -RHS;

    return DoShift<LT, RT,
                   Dir == ShiftDir::Left ? ShiftDir::Right : ShiftDir::Left>(
        S, OpPC, LHS, RHS, Result);
  }
```

DoShift() calls itself when RHS is negative. If we ignore the value, then RHS 
still remains negative and the function will keep recursively calling itself 
until a segfault occurs. This is actually what was happening in the first place 
as well, since `RHS = -RHS` was having no effect if the value of RHS was 
INTXX_MIN. 

I hope this answers your question!




https://github.com/llvm/llvm-project/pull/176390
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to