[clang] Fieldregion descript name (PR #112313)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 15 03:19:00 PDT 2024
================
@@ -751,12 +751,27 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) const {
}
// Get variable name.
- if (R && R->canPrintPrettyAsExpr()) {
- R->printPrettyAsExpr(os);
- if (UseQuotes)
- return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
- else
+ if (R) {
+ // MemRegion can be pretty printed.
+ if (R->canPrintPrettyAsExpr()) {
+ R->printPrettyAsExpr(os);
+ if (UseQuotes)
+ return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
return (llvm::Twine(os.str()) + ArrayIndices).str();
+ }
+
+ // FieldRegion may have ElementRegion as SuperRegion.
+ if (const clang::ento::FieldRegion *FR =
+ R->getAs<clang::ento::FieldRegion>()) {
+ std::string Super = FR->getSuperRegion()->getDescriptiveName(false);
----------------
steakhal wrote:
```suggestion
if (const auto *FR = R->getAs<FieldRegion>()) {
std::string Super = FR->getSuperRegion()->getDescriptiveName(/*UseQuotes=*/false);
```
We prefer not spelling out the type if the line already spells it. We don't need to use fully qualified names, as we are already within the `ento` namespace. We usually use named arguments for bool parameters, to make it more descriptive.
Why are `FieldRegions` so special? Couldn't we do something more generic? I wonder if we could use something like a visitor to bring some structure to this function. This starts to look really messy to me, without evidence that we couldn't do something better. WDYT?
https://github.com/llvm/llvm-project/pull/112313
More information about the cfe-commits
mailing list