[clang] 183b6b5 - [clang][Interp] Ignore unnamed bitfields when checking init

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 08:29:37 PST 2024


Author: Timm Bäder
Date: 2024-02-27T17:29:19+01:00
New Revision: 183b6b56f2602ea171502f9f2843c2c1caca2919

URL: https://github.com/llvm/llvm-project/commit/183b6b56f2602ea171502f9f2843c2c1caca2919
DIFF: https://github.com/llvm/llvm-project/commit/183b6b56f2602ea171502f9f2843c2c1caca2919.diff

LOG: [clang][Interp] Ignore unnamed bitfields when checking init

Unnamed bitfields need to be ignored here.

Added: 
    

Modified: 
    clang/lib/AST/Interp/EvaluationResult.cpp
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp b/clang/lib/AST/Interp/EvaluationResult.cpp
index 693ae9ce4a94e6..07b28d07326f90 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -105,6 +105,8 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
       Result &= CheckFieldsInitialized(S, Loc, FieldPtr, FieldPtr.getRecord());
     } else if (FieldType->isIncompleteArrayType()) {
       // Nothing to do here.
+    } else if (F.Decl->isUnnamedBitfield()) {
+      // Nothing do do here.
     } else if (FieldType->isArrayType()) {
       const auto *CAT =
           cast<ConstantArrayType>(FieldType->getAsArrayTypeUnsafe());

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 78c09661c6dd73..5c9c6257965108 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -776,3 +776,26 @@ namespace RewrittenBinaryOperators {
   };
   static_assert(X() < X(), "");
 }
+
+namespace GH61417 {
+struct A {
+  unsigned x : 1;
+  unsigned   : 0;
+  unsigned y : 1;
+
+  constexpr A() : x(0), y(0) {}
+  bool operator==(const A& rhs) const noexcept = default;
+};
+
+void f1() {
+  constexpr A a, b;
+  constexpr bool c = (a == b); // no diagnostic, we should not be comparing the
+                               // unnamed bit-field which is indeterminate
+}
+
+void f2() {
+    A a, b;
+    bool c = (a == b); // no diagnostic nor crash during codegen attempting to
+                       // access info for unnamed bit-field
+}
+}


        


More information about the cfe-commits mailing list