[clang] 9141e1c - [clang][Interp] Gracefully handle bitcasts to non-primitive types

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 02:08:46 PDT 2024


Author: Timm Bäder
Date: 2024-04-16T11:08:30+02:00
New Revision: 9141e1c24f87e5735bc4178a018eba4bdf2750aa

URL: https://github.com/llvm/llvm-project/commit/9141e1c24f87e5735bc4178a018eba4bdf2750aa
DIFF: https://github.com/llvm/llvm-project/commit/9141e1c24f87e5735bc4178a018eba4bdf2750aa.diff

LOG: [clang][Interp] Gracefully handle bitcasts to non-primitive types

We were calling classfiyPrim() instead of classify().

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/vectors.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 01ec31e4077f70..5866228663dca2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -262,7 +262,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
       return this->discard(SubExpr);
 
     std::optional<PrimType> FromT = classify(SubExpr->getType());
-    std::optional<PrimType> ToT = classifyPrim(CE->getType());
+    std::optional<PrimType> ToT = classify(CE->getType());
     if (!FromT || !ToT)
       return false;
 

diff  --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp
index 8afef3c897bff7..fb5787a9eda9a9 100644
--- a/clang/test/AST/Interp/vectors.cpp
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
 // RUN: %clang_cc1 -verify=ref,both %s
 
-// both-no-diagnostics
+// ref-no-diagnostics
 
 typedef int __attribute__((vector_size(16))) VI4;
 constexpr VI4 A = {1,2,3,4};
@@ -20,3 +20,9 @@ namespace Vector {
   }
   constexpr auto v2 = g(4);
 }
+
+/// FIXME: We need to support BitCasts between vector types.
+namespace {
+  typedef float __attribute__((vector_size(16))) VI42;
+  constexpr VI42 A2 = A; // expected-error {{must be initialized by a constant expression}}
+}


        


More information about the cfe-commits mailing list