================
@@ -7932,6 +7932,35 @@ ExprResult Sema::PerformQualificationConversion(Expr *E, 
QualType Ty,
   return ImpCastExprToType(E, Ty, CK, VK, /*BasePath=*/nullptr, CCK);
 }
 
+static bool containsNonNullPointer(const APValue &Val) {
+  if (Val.isStruct()) {
+    unsigned int N = Val.getStructNumFields();
+    for (unsigned int I = 0; I < N; I++) {
+      if (containsNonNullPointer(Val.getStructField(I)))
+        return true;
+    }
+  } else if (Val.isUnion()) {
+    const APValue &UV = Val.getUnionValue();
+    return containsNonNullPointer(UV);
+  } else if (Val.isLValue() && !Val.isNullPointer()) {
+    return true;
+  }
+  return false;
+}
+
+// C23 6.7.1p6: If an object or subobject declared with storage-class
+// specifier constexpr has pointer, integer, or arithmetic type, any
+// explicit initializer value for it shall be null, an integer
+// constant expression, or an arithmetic constant expression,
+// respectively.
+static bool rejectConstexprValueInC(Sema &S, const APValue &Val) {
+  assert(S.getLangOpts().C23);
+  if (containsNonNullPointer(Val)) {
+    return true;
+  }
+  return false;
----------------
aalmkainzi wrote:

the function only makes sense to be called if C23 or later, I thought an assert 
was a good idea.

I refactored the logic into a seperate function so in the future we can just do:
```C
{
  if (S.getLangOpts().C2y) {
    // C2y specific rules
  } else {
    containsNonNullPointer(Val)) {
    return true;
  }
  return false;
}
```

https://github.com/llvm/llvm-project/pull/230477
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to