[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG78e774e0c827: [clang][Interp] Handle __extension__ unary operators (authored by tbaeder). Changed prior to commit: https://reviews.llvm.org/D148690?vs=514844=544207#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/literals.cpp Index: clang/test/AST/Interp/literals.cpp === --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -880,5 +880,16 @@ static_assert(strings_match(__func__, "foo"), ""); static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), ""); } + + constexpr char heh(unsigned index) { +__FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +__extension__ __FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +return __FUNCTION__[index]; + } + static_assert(heh(0) == 'h', ""); + static_assert(heh(1) == 'e', ""); + static_assert(heh(2) == 'h', ""); #endif } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2004,6 +2004,9 @@ case UO_Real: // __real x case UO_Imag: // __imag x case UO_Extension: +if (DiscardResult) + return this->discard(SubExpr); +return this->visit(SubExpr); case UO_Coawait: assert(false && "Unhandled opcode"); } Index: clang/test/AST/Interp/literals.cpp === --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -880,5 +880,16 @@ static_assert(strings_match(__func__, "foo"), ""); static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), ""); } + + constexpr char heh(unsigned index) { +__FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +__extension__ __FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +return __FUNCTION__[index]; + } + static_assert(heh(0) == 'h', ""); + static_assert(heh(1) == 'e', ""); + static_assert(heh(2) == 'h', ""); #endif } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2004,6 +2004,9 @@ case UO_Real: // __real x case UO_Imag: // __imag x case UO_Extension: +if (DiscardResult) + return this->discard(SubExpr); +return this->visit(SubExpr); case UO_Coawait: assert(false && "Unhandled opcode"); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
tbaeder added inline comments. Comment at: clang/test/AST/Interp/literals.cpp:791 +#endif return __FUNCTION__[index]; } aaron.ballman wrote: > tbaeder wrote: > > erichkeane wrote: > > > tbaeder wrote: > > > > It's weird that the above two statements warn about using > > > > `__FUNCTION__` and the return statement doesn't. > > > Aren't they warning about it being 'unused'? If so, the 'return' uses > > > them... > > Right, my message wasn't clear but I meant the c++14 extension diagnostic: > > https://godbolt.org/z/Kso8qv7jh > That is pretty strange, tbh. Might be worth investigating in a follow-up. Yeah, in `CheckConstexprFunctionStmt` in `SemaDeclCXX.cpp`, the return expression is not checked. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM Comment at: clang/test/AST/Interp/literals.cpp:791 +#endif return __FUNCTION__[index]; } tbaeder wrote: > erichkeane wrote: > > tbaeder wrote: > > > It's weird that the above two statements warn about using `__FUNCTION__` > > > and the return statement doesn't. > > Aren't they warning about it being 'unused'? If so, the 'return' uses > > them... > Right, my message wasn't clear but I meant the c++14 extension diagnostic: > https://godbolt.org/z/Kso8qv7jh That is pretty strange, tbh. Might be worth investigating in a follow-up. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
tbaeder added inline comments. Comment at: clang/test/AST/Interp/literals.cpp:791 +#endif return __FUNCTION__[index]; } erichkeane wrote: > tbaeder wrote: > > It's weird that the above two statements warn about using `__FUNCTION__` > > and the return statement doesn't. > Aren't they warning about it being 'unused'? If so, the 'return' uses them... Right, my message wasn't clear but I meant the c++14 extension diagnostic: https://godbolt.org/z/Kso8qv7jh Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
erichkeane added inline comments. Comment at: clang/test/AST/Interp/literals.cpp:791 +#endif return __FUNCTION__[index]; } tbaeder wrote: > It's weird that the above two statements warn about using `__FUNCTION__` and > the return statement doesn't. Aren't they warning about it being 'unused'? If so, the 'return' uses them... Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
tbaeder added inline comments. Comment at: clang/test/AST/Interp/literals.cpp:791 +#endif return __FUNCTION__[index]; } It's weird that the above two statements warn about using `__FUNCTION__` and the return statement doesn't. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148690/new/ https://reviews.llvm.org/D148690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators
tbaeder created this revision. tbaeder added reviewers: aaron.ballman, tahonermann, shafik, erichkeane. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. AFAIK this is just used to suppress warnings, so ignore it altogether. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148690 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/literals.cpp Index: clang/test/AST/Interp/literals.cpp === --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -782,6 +782,12 @@ namespace PredefinedExprs { constexpr char heh(unsigned index) { +#if __cplusplus >= 201402L +__FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +__extension__ __FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +#endif return __FUNCTION__[index]; } static_assert(heh(0) == 'h', ""); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1856,6 +1856,9 @@ case UO_Real: // __real x case UO_Imag: // __imag x case UO_Extension: +if (DiscardResult) + return this->discard(SubExpr); +return this->visit(SubExpr); case UO_Coawait: assert(false && "Unhandled opcode"); } Index: clang/test/AST/Interp/literals.cpp === --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -782,6 +782,12 @@ namespace PredefinedExprs { constexpr char heh(unsigned index) { +#if __cplusplus >= 201402L +__FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +__extension__ __FUNCTION__; // ref-warning {{result unused}} \ +// expected-warning {{result unused}} +#endif return __FUNCTION__[index]; } static_assert(heh(0) == 'h', ""); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1856,6 +1856,9 @@ case UO_Real: // __real x case UO_Imag: // __imag x case UO_Extension: +if (DiscardResult) + return this->discard(SubExpr); +return this->visit(SubExpr); case UO_Coawait: assert(false && "Unhandled opcode"); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits