-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][ast]: Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump(). #135178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: None (YLChenZ) ChangesCloses #134996. The crash about Before the patch:
After the patch:
Full diff: https://github.com/llvm/llvm-project/pull/135178.diff 2 Files Affected:
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index be8d609974d81..0849e5642f006 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -738,6 +738,10 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
else if (const auto *BE = B.dyn_cast<const Expr *>()) {
OS << BE->getStmtClassName() << ' ';
dumpPointer(BE);
+ } else if (B.is<TypeInfoLValue>()) {
+ OS << "TypeInfoLValue";
+ } else if (B.is<DynamicAllocLValue>()) {
+ OS << "DynamicAllocLValue";
} else {
const auto *VDB = B.get<const ValueDecl *>();
OS << VDB->getDeclKindName() << "Decl";
diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp
index 224caddb3eabe..7e520254da41a 100644
--- a/clang/test/AST/ast-dump-APValue-lvalue.cpp
+++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp
@@ -23,6 +23,10 @@ struct F {
};
F f;
+namespace std {
+ class type_info;
+}
+
void Test(int (&arr)[10]) {
constexpr int *pi = &i;
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pi 'int *const' constexpr cinit
@@ -45,6 +49,10 @@ void Test(int (&arr)[10]) {
// CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=2, HasPath=1, PathLength=2, Path=({{.*}}, 2)
constexpr const int *n = nullptr;
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
- // CHECK-NEXT: |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
+ // CHECK-NEXT: | |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
+
+ constexpr const std::type_info* pti = &typeid(int);
+ // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
+ // CHECK-NEXT: |-value: LValue Base=TypeInfoLValue, Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
}
|
clang/lib/AST/TextNodeDumper.cpp
Outdated
} else if (B.is<TypeInfoLValue>()) { | ||
OS << "TypeInfoLValue"; | ||
} else if (B.is<DynamicAllocLValue>()) { | ||
OS << "DynamicAllocLValue"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to print more information about them.
I don't think we can test diff --git i/clang/lib/AST/ExprConstant.cpp w/clang/lib/AST/ExprConstant.cpp
index d1cc722fb794..df52ff82ea2a 100644
--- i/clang/lib/AST/ExprConstant.cpp
+++ w/clang/lib/AST/ExprConstant.cpp
@@ -17087,6 +17087,8 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
return false;
}
+ Value.dump();
+
// At this point, any lifetime-extended temporaries are completely
// initialized.
Info.performLifetimeExtension(); then you can compile constexpr int *m = new int(12); to reproduce it. |
Okay, I got it. Already reproduced the crash.
|
@tbaederr It seems to only dump their type, like this: case APValue::LValue: {
(void)Context;
OS << "LValue Base=";
APValue::LValueBase B = Value.getLValueBase();
...
} else if (B.is<TypeInfoLValue>()) {
OS << "TypeInfoLValue";
const auto BTI = B.get<TypeInfoLValue>();
BTI.print(OS, PrintPolicy);
} else if (B.is<DynamicAllocLValue>()) {
OS << "DynamicAllocLValue";
auto BDA = B.getDynamicAllocType();
dumpType(BDA);
} //test.cpp
#include <typeinfo>
constexpr const std::type_info* val = &typeid(int);
//DAtest.cpp
constexpr int *m = new int(42);
|
6368e47
to
23d850d
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
Can you merge this or do you need to someone else to do it for you? |
@tbaederr I don't have access to merge pr. It should require some help to merge. |
…Value::dump(). (llvm#135178) Closes llvm#134996. The crash about `TypeInfoLValue` is https://godbolt.org/z/73WY31s55. After the patch: ```cpp //test.cpp #include <typeinfo> constexpr const std::type_info* val = &typeid(int); ``` ``` lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only test.cpp LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=() ``` ```cpp //DAtest.cpp constexpr int *m = new int(42); ``` ``` lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only DAtest.cpp LValue Base=DynamicAllocLValue 'int', Null=0, Offset=0, HasPath=1, PathLength=0, Path=() ```
Closes #134996.
The crash about
TypeInfoLValue
is https://godbolt.org/z/73WY31s55.After the patch: