[clang] [clang][Interp] Bail out on missing ComparisonCategoryInfo (PR #80131)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 03:56:06 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Instead of asserting. This can happen in real-world code.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+2-1) 
- (modified) clang/test/Sema/struct-cast.c (+1) 


``````````diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8188d6f7f5c24..a1c458a09e5ae 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -379,7 +379,8 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
       return true;
     const ComparisonCategoryInfo *CmpInfo =
         Ctx.getASTContext().CompCategories.lookupInfoForType(BO->getType());
-    assert(CmpInfo);
+    if (!CmpInfo)
+      return false;
 
     // We need a temporary variable holding our return value.
     if (!Initializing) {
diff --git a/clang/test/Sema/struct-cast.c b/clang/test/Sema/struct-cast.c
index 74d00c42c295e..05e5fa4f92ca7 100644
--- a/clang/test/Sema/struct-cast.c
+++ b/clang/test/Sema/struct-cast.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fsyntax-only %s -fexperimental-new-constant-interpreter -verify
 // expected-no-diagnostics
 
 struct S {

``````````

</details>


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


More information about the cfe-commits mailing list