================
@@ -1451,6 +1451,8 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
     DestinationSize = ComputeSizeArgument(0);
     const Expr *LenArg = TheCall->getArg(1)->IgnoreParenImpCasts();
     const Expr *Dest = TheCall->getArg(0)->IgnoreParenImpCasts();
+    if (const auto *DestCast = dyn_cast_or_null<CastExpr>(Dest))
+      Dest = DestCast->getSubExprAsWritten();
----------------
BgZun wrote:

TLDR: So the ExpressionIDs for `Dest` and `LenArg` CAN match

If we use `getSubExpr()` we also grab all implicit cast expressions. This will 
cause a mismatch when comparing the `LenArg` and `Dest`  expressionIDs (The IDs 
are generated in `CheckSizeofMemaccessArgument` using `Profile()`)
For example when we use `getSubExpr()` the dump of `a` in  `snprintf((char *)a, 
sizeof(a), "%s", b); ` will be: 
```
ImplicitCastExpr 0x10afa3c8 'char *' <LValueToRValue> part_of_explicit_cast
`-DeclRefExpr 0x10afa390 'char *' lvalue Var 0x10af9bc8 'a' 'char *'
```

But if we use `getSubExprAsWritten` the dump will be:
```
DeclRefExpr 0xf6f8390 'char *' lvalue Var 0xf6f7bc8 'a' 'char *'
```

https://github.com/llvm/llvm-project/pull/170637
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to