tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
The `invBool` op here expects a bool operand, but in C, the operand might be of a different type (usually int). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157200 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/c.c Index: clang/test/AST/Interp/c.c =================================================================== --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -9,6 +9,8 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(1 && 1.0, ""); _Static_assert( (5 > 4) + (3 > 2) == 2, ""); +_Static_assert(!!1.0, ""); +_Static_assert(!!1, ""); /// FIXME: Should also be rejected in the new interpreter int a = (1 == 1 ? 5 : 3); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2481,10 +2481,18 @@ return this->emitStore(*T, E); } case UO_LNot: // !x - if (!this->visit(SubExpr)) + if (DiscardResult) + return this->discard(SubExpr); + + if (!this->visitBool(SubExpr)) return false; - // The Inv doesn't change anything, so skip it if we don't need the result. - return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E); + + if (!this->emitInvBool(E)) + return false; + + if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool) + return this->emitCast(PT_Bool, ET, E); + return true; case UO_Minus: // -x if (!this->visit(SubExpr)) return false;
Index: clang/test/AST/Interp/c.c =================================================================== --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -9,6 +9,8 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(1 && 1.0, ""); _Static_assert( (5 > 4) + (3 > 2) == 2, ""); +_Static_assert(!!1.0, ""); +_Static_assert(!!1, ""); /// FIXME: Should also be rejected in the new interpreter int a = (1 == 1 ? 5 : 3); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2481,10 +2481,18 @@ return this->emitStore(*T, E); } case UO_LNot: // !x - if (!this->visit(SubExpr)) + if (DiscardResult) + return this->discard(SubExpr); + + if (!this->visitBool(SubExpr)) return false; - // The Inv doesn't change anything, so skip it if we don't need the result. - return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E); + + if (!this->emitInvBool(E)) + return false; + + if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool) + return this->emitCast(PT_Bool, ET, E); + return true; case UO_Minus: // -x if (!this->visit(SubExpr)) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits