[clang] [clang][bytecode] Discard NullToPointer cast SubExpr (PR #104782)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 19 07:15:52 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

So we still properly abort if they fail.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2) 
- (modified) clang/test/AST/ByteCode/codegen.cpp (+9) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 53144a50ccf4a9..c839364d4c8d25 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -327,6 +327,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
 
   case CK_NullToPointer:
   case CK_NullToMemberPointer: {
+    if (!this->discard(SubExpr))
+      return false;
     if (DiscardResult)
       return true;
 
diff --git a/clang/test/AST/ByteCode/codegen.cpp b/clang/test/AST/ByteCode/codegen.cpp
index 920a5ad7ba3e8f..9fac28a52d3150 100644
--- a/clang/test/AST/ByteCode/codegen.cpp
+++ b/clang/test/AST/ByteCode/codegen.cpp
@@ -64,3 +64,12 @@ namespace Bitfield {
   // CHECK: store ptr @_ZGRN8Bitfield1rE_, ptr @_ZN8Bitfield1rE, align 8
   int &&r = S().a;
 }
+
+namespace Null {
+  decltype(nullptr) null();
+  // CHECK: call {{.*}} @_ZN4Null4nullEv(
+  int *p = null();
+  struct S {};
+  // CHECK: call {{.*}} @_ZN4Null4nullEv(
+  int S::*q = null();
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/104782


More information about the cfe-commits mailing list