Skip to content

Commit eda58ac

Browse files
committed
Improve the attribute language option interface somewhat; NFCi.
The name field is optional if the custom code is supplied, so this updates the documentation for LangOpt and introduces a tablegen warning if both custom code and a language option name are supplied.
1 parent b8b8f04 commit eda58ac

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class SubjectList<list<AttrSubject> subjects, SubjectDiag diag = WarnDiag,
312312
}
313313

314314
class LangOpt<string name, code customCode = [{}]> {
315+
// The language option to test; ignored when custom code is supplied.
315316
string Name = name;
316317

317318
// A custom predicate, written as an expression evaluated in a context with
@@ -323,15 +324,15 @@ def Borland : LangOpt<"Borland">;
323324
def CUDA : LangOpt<"CUDA">;
324325
def HIP : LangOpt<"HIP">;
325326
def SYCL : LangOpt<"SYCLIsDevice">;
326-
def COnly : LangOpt<"COnly", "!LangOpts.CPlusPlus">;
327+
def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
327328
def CPlusPlus : LangOpt<"CPlusPlus">;
328329
def OpenCL : LangOpt<"OpenCL">;
329330
def RenderScript : LangOpt<"RenderScript">;
330331
def ObjC : LangOpt<"ObjC">;
331332
def BlocksSupported : LangOpt<"Blocks">;
332333
def ObjCAutoRefCount : LangOpt<"ObjCAutoRefCount">;
333-
def ObjCNonFragileRuntime : LangOpt<"ObjCNonFragileRuntime",
334-
"LangOpts.ObjCRuntime.allowsClassStubs()">;
334+
def ObjCNonFragileRuntime
335+
: LangOpt<"", "LangOpts.ObjCRuntime.allowsClassStubs()">;
335336

336337
// Language option for CMSE extensions
337338
def Cmse : LangOpt<"Cmse">;

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,11 @@ static std::string GenerateTestExpression(ArrayRef<Record *> LangOpts) {
19801980
Test += "(";
19811981
Test += Code;
19821982
Test += ")";
1983+
if (!E->getValueAsString("Name").empty()) {
1984+
PrintWarning(
1985+
E->getLoc(),
1986+
"non-empty 'Name' field ignored because 'CustomCode' was supplied");
1987+
}
19831988
} else {
19841989
Test += "LangOpts.";
19851990
Test += E->getValueAsString("Name");

0 commit comments

Comments
 (0)