[llvm-bugs] [Bug 52296] alpha.core.BoolAssignment does not work (at least for C and C++)

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 28 03:34:57 PDT 2021


Balazs Benics <balazs.benics at sigmatechnology.se> changed:

           What    |Removed                     |Added
         Resolution|---                         |INVALID
             Status|REOPENED                    |RESOLVED

--- Comment #3 from Balazs Benics <balazs.benics at sigmatechnology.se> ---
It seems like the corresponding AST looks like this:
    |-DeclStmt <line:6:3, col:16>
    | `-VarDecl <col:3, col:15> col:8 foo 'BOOL':'int' cinit
    |   `-UnaryOperator <col:14, col:15> 'int' prefix '-'
    |     `-IntegerLiteral <col:15> 'int' 1
    |-DeclStmt <include/stdbool.h:20:15, line:7:17>
    | `-VarDecl include/stdbool.h:20:15, line:7:16> col:9 bar 'bool' cinit
    |   `-ImplicitCastExpr <col:15, col:16> 'bool' <IntegralToBoolean>
    |     `-UnaryOperator <col:15, col:16> 'int' prefix '-'
    |       `-IntegerLiteral <col:16> 'int' 1
    `-DeclStmt <line:8:3, col:16>
      `-VarDecl <col:3, col:15> col:8 qaz 'bool' cinit
        `-ImplicitCastExpr <col:14, col:15> 'bool' <IntegralToBoolean>
          `-UnaryOperator <col:14, col:15> 'int' prefix '-'
            `-IntegerLiteral <col:15> 'int' 1

And, by calling the `getType()->isUnsignedIntegerOrEnumerationType()` on the
`ImplicitCastExpr` nodes, I get `true`.
This suggests to me that the behavior is actually correct, and the implicit
conversion transforms `-1` into `1` according to the C++ language rules.
As a result, `bar` and `qaz` are actually initialized to `true`.

That being said, we should probably extend the checker documentation to
highlight this behavior.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211028/b10afd88/attachment.html>

More information about the llvm-bugs mailing list