This is an archive of the discontinued LLVM Phabricator instance.

[clang][ConstExprEmitter] handle Unary Not on integers
Needs ReviewPublic

Authored by nickdesaulniers on Aug 8 2023, 1:14 PM.

Details

Reviewers
efriedma
Summary

Consider the following statement:

int x = ~0;

With the following AST:

`-VarDecl 0x5647bdb12d60 <x.c:1:1, col:10> col:5 x 'int' cinit
  `-UnaryOperator 0x5647bdb12e30 <col:9, col:10> 'int' prefix '~' cannot overflow
    `-IntegerLiteral 0x5647bdb12e10 <col:10> 'int' 0

Return the evaluation of the subexpression bitwise inverted.

Link: https://github.com/ClangBuiltLinux/linux/issues/1906

Diff Detail

Event Timeline

nickdesaulniers created this revision.Aug 8 2023, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 1:14 PM
nickdesaulniers requested review of this revision.Aug 8 2023, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 1:14 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
nickdesaulniers added inline comments.Aug 8 2023, 1:22 PM
clang/lib/CodeGen/CGExprConstant.cpp
1402

A lot of these visitor methods for UnaryOperator are going to look almost the same; I think I might prefer to have a VisitUnaryOperator method instead, and simply switch on the kind of operator.

But perhaps, I should flush out more of these methods, then do such refactoring? WDYT @efriedma