Author: Timm Bäder
Date: 2024-02-18T16:31:40+01:00
New Revision: ba27c3963d785a023cc8963ec3b6f508fe31527e

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

LOG: [clang][Interp] Classify correct type for compound shifts

RT must be the type of the RHS, otherwise this later fails when
we set the RHS value to the temporary variable.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 72789d9d348144..6ad75d4e034a9d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1468,7 +1468,7 @@ bool 
ByteCodeExprGen<Emitter>::VisitCompoundAssignOperator(
   std::optional<PrimType> LHSComputationT =
       classify(E->getComputationLHSType());
   std::optional<PrimType> LT = classify(LHS->getType());
-  std::optional<PrimType> RT = classify(E->getComputationResultType());
+  std::optional<PrimType> RT = classify(RHS->getType());
   std::optional<PrimType> ResultT = classify(E->getType());
 
   if (!LT || !RT || !ResultT || !LHSComputationT)

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index cf71e7145c2742..e5201b3f8bbef7 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -188,3 +188,12 @@ namespace shifts {
                           // ref-cxx17-error {{not an integral constant 
expression}} \
                           // ref-cxx17-note {{in call to 'foo(2)'}}
 };
+
+namespace LongInt {
+  constexpr int f() {
+    int a = 1;
+    a <<= (long)0;
+    return 1;
+  }
+  static_assert(f() == 1, "");
+};


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to