[clang] 93d4fb0 - [clang][Interp] Support floats in APValues
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 23:15:48 PDT 2024
Author: Timm Bäder
Date: 2024-06-12T08:15:36+02:00
New Revision: 93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac
URL: https://github.com/llvm/llvm-project/commit/93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac
DIFF: https://github.com/llvm/llvm-project/commit/93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac.diff
LOG: [clang][Interp] Support floats in APValues
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 820e4cc44a7bc..1393ef1f2ec35 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3223,6 +3223,8 @@ bool ByteCodeExprGen<Emitter>::visitAPValue(const APValue &Val,
assert(!DiscardResult);
if (Val.isInt())
return this->emitConst(Val.getInt(), ValType, E);
+ else if (Val.isFloat())
+ return this->emitConstFloat(Val.getFloat(), E);
if (Val.isLValue()) {
if (Val.isNullPointer())
@@ -3253,7 +3255,7 @@ bool ByteCodeExprGen<Emitter>::visitAPValueInitializer(const APValue &Val,
const APValue &F = Val.getStructField(I);
const Record::Field *RF = R->getField(I);
- if (F.isInt() || F.isLValue() || F.isMemberPointer()) {
+ if (F.isInt() || F.isFloat() || F.isLValue() || F.isMemberPointer()) {
PrimType T = classifyPrim(RF->Decl->getType());
if (!this->visitAPValue(F, T, E))
return false;
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index 0a89c81bafd57..8a18f7a2a4890 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1479,4 +1479,17 @@ namespace VirtOperator {
};
constexpr bool cmp_base_derived = D() == D(); // both-warning {{ambiguous}}
}
+
+namespace FloatAPValue {
+ struct ClassTemplateArg {
+ int a;
+ float f;
+ };
+ template<ClassTemplateArg A> struct ClassTemplateArgTemplate {
+ static constexpr const ClassTemplateArg &Arg = A;
+ };
+ ClassTemplateArgTemplate<ClassTemplateArg{1, 2.0f}> ClassTemplateArgObj;
+ template<const ClassTemplateArg&> struct ClassTemplateArgRefTemplate {};
+ ClassTemplateArgRefTemplate<ClassTemplateArgObj.Arg> ClassTemplateArgRefObj;
+}
#endif
More information about the cfe-commits
mailing list