[clang] [clang][Interp] Bail out on missing ComparisonCategoryInfo (PR #80131)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 31 03:55:35 PST 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/80131
Instead of asserting. This can happen in real-world code.
>From 3548cdb9907a44c25da61887b2f8e83268e3c2d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 31 Jan 2024 12:53:39 +0100
Subject: [PATCH] [clang][Interp] Bail out on missing ComparisonCategoryInfo
Instead of asserting. This can happen in real-world code.
---
clang/lib/AST/Interp/ByteCodeExprGen.cpp | 3 ++-
clang/test/Sema/struct-cast.c | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
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 {
More information about the cfe-commits
mailing list