[clang] [clang][dataflow] fix assert in `Environment::getResultObjectLocation` (PR #79608)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 30 11:44:11 PST 2024
================
@@ -2735,6 +2735,41 @@ TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) {
});
}
+// This test ensures that CXXOperatorCallExpr returning prvalues are correctly
+// handled by the transfer functions, especially that `getResultObjectLocation`
+// correctly returns a storage location for those.
+TEST(TransferTest, ResultObjectLocationForCXXOperatorCallExpr) {
+ std::string Code = R"(
+ struct A {
+ virtual ~A() = default;
+ A operator+(int a) { return A(); }
+ };
+
+ void target() {
+ A a;
+ a + 3;
+ (void)0; // [[p]]
+ }
+ )";
+ using ast_matchers::cxxOperatorCallExpr;
+ using ast_matchers::match;
+ using ast_matchers::selectFirst;
+ using ast_matchers::traverse;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ auto *CallExpr = selectFirst<CXXOperatorCallExpr>(
+ "call_expr",
+ match(traverse(TK_AsIs, cxxOperatorCallExpr().bind("call_expr")),
+ ASTCtx));
----------------
martinboehme wrote:
I don't think you need `TK_AsIs` here, as the `CXXOperatorCallExpr` is spelled in the source. (If this doesn't work, please ignore.)
```suggestion
match(cxxOperatorCallExpr().bind("call_expr"), ASTCtx));
```
https://github.com/llvm/llvm-project/pull/79608
More information about the cfe-commits
mailing list