================
@@ -3055,47 +3056,139 @@ Address
CIRGenFunction::createDefaultAlignTempAlloca(mlir::Type ty,
return createTempAlloca(ty, align, loc, name);
}
+/// Given an object of the given canonical type, can we safely copy a
+/// value out of it based on its initializer?
+static bool isConstantEmittableObjectType(QualType type) {
+ assert(type.isCanonical());
+ assert(!type->isReferenceType());
+
+ // Must be const-qualified but non-volatile.
+ Qualifiers qs = type.getLocalQualifiers();
+ if (!qs.hasConst() || qs.hasVolatile())
+ return false;
+
+ // Otherwise, all object types satisfy this except C++ classes with
+ // mutable subobjects or non-trivial copy/destroy behavior.
+ if (const auto *rt = dyn_cast<clang::RecordType>(type))
+ if (const auto *rd = dyn_cast<CXXRecordDecl>(rt->getDecl())) {
+ rd = rd->getDefinitionOrSelf();
+ if (rd->hasMutableFields() || !rd->isTrivial())
+ return false;
+ }
+
+ return true;
+}
+
+/// Can we constant-emit a load of a reference to a variable of the
+/// given type? This is different from predicates like
+/// Decl::mightBeUsableInConstantExpressions because we do want it to apply
+/// in situations that don't necessarily satisfy the language's rules
+/// for this (e.g. C++'s ODR-use rules). For example, we want to able
+/// to do this with const float variables even if those variables
+/// aren't marked 'constexpr'.
+enum ConstantEmissionKind {
+ CEK_None,
+ CEK_AsReferenceOnly,
+ CEK_AsValueOrReference,
+ CEK_AsValueOnly
+};
+static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type) {
----------------
koparasy wrote:
Done in f3296ce
https://github.com/llvm/llvm-project/pull/231689
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits