[clang] [Clang][WIP] Constant Expressions inside of gcc'asm strings (PR #131003)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 11:43:54 PDT 2025


================
@@ -17928,43 +17928,70 @@ std::optional<std::string> Expr::tryEvaluateString(ASTContext &Ctx) const {
   return {};
 }
 
-bool Expr::EvaluateCharRangeAsString(std::string &Result,
-                                     const Expr *SizeExpression,
-                                     const Expr *PtrExpression, ASTContext &Ctx,
-                                     EvalResult &Status) const {
-  LValue String;
-  EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
-  Info.InConstantContext = true;
+template <typename T>
+static bool EvaluateCharRangeAsStringImpl(const Expr*, T& Result,
+                                          const Expr *SizeExpression,
+                                          const Expr *PtrExpression, ASTContext &Ctx,
+                                          Expr::EvalResult &Status) {
+    LValue String;
+    EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
+    Info.InConstantContext = true;
 
-  FullExpressionRAII Scope(Info);
-  APSInt SizeValue;
-  if (!::EvaluateInteger(SizeExpression, SizeValue, Info))
-    return false;
+    FullExpressionRAII Scope(Info);
+    APSInt SizeValue;
+    if (!::EvaluateInteger(SizeExpression, SizeValue, Info))
+      return false;
 
-  uint64_t Size = SizeValue.getZExtValue();
+    uint64_t Size = SizeValue.getZExtValue();
 
-  if (!::EvaluatePointer(PtrExpression, String, Info))
-    return false;
+    if constexpr(std::is_same_v<APValue, T>)
+        Result = APValue(APValue::UninitArray{}, Size, Size);
+    //else
----------------
erichkeane wrote:

Eh?

https://github.com/llvm/llvm-project/pull/131003


More information about the cfe-commits mailing list