[clang] [AMDGPU] Add builtin to test for constant memory (PR #209679)

Shilei Tian via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 16 09:03:54 PDT 2026


================
@@ -28,12 +28,69 @@
 #include "llvm/Support/AtomicOrdering.h"
 #include "llvm/TargetParser/AMDGPUTargetParser.h"
 #include <cstdint>
+#include <optional>
 #include <utility>
 
 namespace clang {
 
 SemaAMDGPU::SemaAMDGPU(Sema &S) : SemaBase(S) {}
 
+namespace {
+
+static std::pair<StringRef, SourceLocation>
+getExplicitAMDGPUSectionName(const VarDecl *D) {
+  if (auto *SA = D->getAttr<SectionAttr>())
+    return {SA->getName(), SA->getLocation()};
+  return {StringRef(), SourceLocation()};
+}
+
+static bool isDependentVarDecl(const VarDecl *D) {
+  if (D->getType()->isDependentType())
+    return true;
+  if (const auto *Init = D->getInit())
+    return Init->isValueDependent();
+  return false;
+}
+
+} // namespace
+
+void SemaAMDGPU::checkConstantAddressSpaceSection(VarDecl *VD) {
+  if (!SemaRef.Context.getTargetInfo().getTriple().isAMDGCN())
+    return;
+  std::optional<StringRef> ConstantSection =
+      SemaRef.Context.getTargetInfo().getConstantAddressSpaceSectionName();
+  if (!ConstantSection)
----------------
shiltian wrote:

I don't understand this whole Sema thing. If this is supposed to be a runtime check, how is compiler's sema involved here?

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


More information about the cfe-commits mailing list