llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (YLChenZ)

<details>
<summary>Changes</summary>

Closes #<!-- -->134996.

The crash about `TypeInfoLValue` is https://godbolt.org/z/73WY31s55. The crash 
about `DynamicAllocLValue` I don't know how to reproduce it yet.

Before the patch:
```
......
`-VarDecl 0x118857f0 &lt;&lt;source&gt;:3:1, col:50&gt; col:33 val 'const 
std::type_info *const' constexpr cinit
  |-value: LValue Base=
clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:566: 
decltype(auto) llvm::cast(const From&amp;) [with To = const clang::ValueDecl*; 
From = llvm::PointerUnion&lt;const clang::ValueDecl*, const clang::Expr*, 
clang::TypeInfoLValue, clang::DynamicAllocLValue&gt;]: Assertion 
`isa&lt;To&gt;(Val) &amp;&amp; "cast&lt;Ty&gt;() argument of incompatible 
type!"' failed.
``` 

After the patch:
```
......
`-VarDecl 0x55b81259b750 &lt;test.cpp:3:1, col:50&gt; col:33 val 'const 
std::type_info *const' constexpr cinit
  |-value: LValue Base=TypeInfoLValue, Null=0, Offset=0, HasPath=1, 
PathLength=0, Path=()
  `-UnaryOperator 0x55b81259b7f0 &lt;col:39, col:50&gt; 'const std::type_info 
*' prefix '&amp;' cannot overflow
    `-CXXTypeidExpr 0x55b81259b7d0 &lt;col:40, col:50&gt; 'const 
std::type_info' lvalue
```



---
Full diff: https://github.com/llvm/llvm-project/pull/135178.diff


2 Files Affected:

- (modified) clang/lib/AST/TextNodeDumper.cpp (+4) 
- (modified) clang/test/AST/ast-dump-APValue-lvalue.cpp (+10-2) 


``````````diff
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=()
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/135178
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to