================
@@ -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)
----------------
yxsamliu wrote:
The Sema check is for the section contract, not for evaluating the builtin.
The runtime builtin depends on constant variables being placed in the target
constant section. If a user forces a constant variable into a different
section, the runtime check may give the wrong answer. So this diagnoses that
source pattern early.
Maybe this could be a warning instead of an error if we want to allow users who
do not care about this builtin.
https://github.com/llvm/llvm-project/pull/209679
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits