[clang] [Clang] [Sema] Improve support for `__restrict`-qualified member functions (PR #83855)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 11:09:00 PDT 2024


================
@@ -5052,6 +5052,21 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
 
+  // Propagate '__restrict' properly.
+  if (auto MD = dyn_cast<CXXMethodDecl>(Function)) {
+    bool Restrict = cast<CXXMethodDecl>(PatternDecl)->isEffectivelyRestrict();
+    if (Restrict != MD->getMethodQualifiers().hasRestrict()) {
+      const auto *FPT = MD->getType()->getAs<FunctionProtoType>();
+      FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+      if (Restrict)
+        EPI.TypeQuals.addRestrict();
+      else
+        EPI.TypeQuals.removeRestrict();
+      MD->setType(Context.getFunctionType(FPT->getReturnType(),
+                                          FPT->getParamTypes(), EPI));
+    }
+  }
+
----------------
erichkeane wrote:

It seems to me that this should happen on the Function Declaration instantiation, not the defintion.  Since this should propagate even if the function is not yet defined.

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


More information about the cfe-commits mailing list