Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f071125

Browse files
committed
Reverting r204968 and r204969; while more build bots are happy with the results, some still have link errors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204974 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0608e4e commit f071125

13 files changed

+55
-155
lines changed

include/clang/Basic/Attributes.h

-39
This file was deleted.

include/clang/Basic/CMakeLists.txt

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ clang_tablegen(AttrList.inc -gen-clang-attr-list
2828
SOURCE Attr.td
2929
TARGET ClangAttrList)
3030

31-
clang_tablegen(AttrHasAttributeImpl.inc -gen-clang-attr-has-attribute-impl
32-
-I ${CMAKE_CURRENT_SOURCE_DIR}/../../
33-
SOURCE Attr.td
34-
TARGET ClangAttrHasAttributeImpl
35-
)
36-
3731
# ARM NEON
3832
clang_tablegen(arm_neon.inc -gen-arm-neon-sema
3933
SOURCE arm_neon.td

include/clang/Basic/Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ BUILT_SOURCES = \
66
DiagnosticFrontendKinds.inc DiagnosticLexKinds.inc \
77
DiagnosticParseKinds.inc DiagnosticSemaKinds.inc \
88
DiagnosticSerializationKinds.inc \
9-
AttrHasAttributeImpl.inc \
109
DiagnosticIndexName.inc DiagnosticGroups.inc AttrList.inc arm_neon.inc \
1110
Version.inc
1211

@@ -49,12 +48,6 @@ $(ObjDir)/AttrList.inc.tmp : Attr.td $(CLANG_TBLGEN) $(ObjDir)/.dir
4948
$(Verb) $(ClangTableGen) -gen-clang-attr-list -o $(call SYSPATH, $@) \
5049
-I $(PROJ_SRC_DIR)/../.. $<
5150

52-
$(ObjDir)/AttrHasAttributeImpl.inc.tmp : Attr.td $(CLANG_TBLGEN) \
53-
$(ObjDir)/.dir
54-
$(Echo) "Building Clang __has_attribute implementation with tblgen"
55-
$(Verb) $(ClangTableGen) -gen-clang-attr-has-attribute-impl -o $(call SYSPATH, $@) \
56-
-I $(PROJ_SRC_DIR)/../../ $<
57-
5851
$(ObjDir)/arm_neon.inc.tmp : arm_neon.td $(CLANG_TBLGEN) $(ObjDir)/.dir
5952
$(Echo) "Building Clang arm_neon.inc with tblgen"
6053
$(Verb) $(ClangTableGen) -gen-arm-neon-sema -o $(call SYSPATH, $@) $<

include/clang/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_subdirectory(AST)
22
add_subdirectory(Basic)
33
add_subdirectory(Driver)
4+
add_subdirectory(Lex)
45
add_subdirectory(Parse)
56
add_subdirectory(Sema)
67
add_subdirectory(Serialization)

include/clang/Lex/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
clang_tablegen(AttrSpellings.inc -gen-clang-attr-spelling-list
2+
-I ${CMAKE_CURRENT_SOURCE_DIR}/../../
3+
SOURCE ../Basic/Attr.td
4+
TARGET ClangAttrSpellings
5+
)

include/clang/Lex/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CLANG_LEVEL := ../../..
2+
TD_SRC_DIR = $(PROJ_SRC_DIR)/../Basic
3+
BUILT_SOURCES = AttrSpellings.inc
4+
5+
TABLEGEN_INC_FILES_COMMON = 1
6+
7+
include $(CLANG_LEVEL)/Makefile
8+
9+
$(ObjDir)/AttrSpellings.inc.tmp : $(TD_SRC_DIR)/Attr.td $(CLANG_TBLGEN) \
10+
$(ObjDir)/.dir
11+
$(Echo) "Building Clang attribute spellings with tblgen"
12+
$(Verb) $(ClangTableGen) -gen-clang-attr-spelling-list -o $(call SYSPATH, $@) \
13+
-I $(PROJ_SRC_DIR)/../../ $<

include/clang/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CLANG_LEVEL := ../..
2-
DIRS := AST Basic Driver Parse Sema Serialization
2+
DIRS := AST Basic Driver Lex Parse Sema Serialization
33

44
include $(CLANG_LEVEL)/Makefile
55

lib/Basic/Attributes.cpp

-17
This file was deleted.

lib/Basic/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
44
)
55

66
add_clang_library(clangBasic
7-
Attributes.cpp
87
Builtins.cpp
98
CharInfo.cpp
109
Diagnostic.cpp

lib/Lex/PPMacroExpansion.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "clang/Lex/Preprocessor.h"
16-
#include "clang/Basic/Attributes.h"
1716
#include "clang/Basic/FileManager.h"
1817
#include "clang/Basic/SourceManager.h"
1918
#include "clang/Basic/TargetInfo.h"
@@ -1048,6 +1047,20 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
10481047
.Default(false);
10491048
}
10501049

1050+
/// HasAttribute - Return true if we recognize and implement the attribute
1051+
/// specified by the given identifier.
1052+
static bool HasAttribute(const IdentifierInfo *II, const llvm::Triple &T) {
1053+
StringRef Name = II->getName();
1054+
// Normalize the attribute name, __foo__ becomes foo.
1055+
if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__"))
1056+
Name = Name.substr(2, Name.size() - 4);
1057+
1058+
// FIXME: Do we need to handle namespaces here?
1059+
return llvm::StringSwitch<bool>(Name)
1060+
#include "clang/Lex/AttrSpellings.inc"
1061+
.Default(false);
1062+
}
1063+
10511064
/// EvaluateHasIncludeCommon - Process a '__has_include("path")'
10521065
/// or '__has_include_next("path")' expression.
10531066
/// Returns true if successful.
@@ -1386,8 +1399,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
13861399
// Check for a builtin is trivial.
13871400
Value = FeatureII->getBuiltinID() != 0;
13881401
} else if (II == Ident__has_attribute)
1389-
Value = HasAttribute(AttrSyntax::Generic, nullptr, FeatureII,
1390-
getTargetInfo().getTriple(), getLangOpts());
1402+
Value = HasAttribute(FeatureII, getTargetInfo().getTriple());
13911403
else if (II == Ident__has_extension)
13921404
Value = HasExtension(*this, FeatureII);
13931405
else {

utils/TableGen/ClangAttrEmitter.cpp

+15-75
Original file line numberDiff line numberDiff line change
@@ -1720,16 +1720,22 @@ void EmitClangAttrPCHWrite(RecordKeeper &Records, raw_ostream &OS) {
17201720
OS << " }\n";
17211721
}
17221722

1723-
static void GenerateHasAttrSpellingStringSwitch(
1724-
const std::vector<Record *> &Attrs, raw_ostream &OS,
1725-
const std::string &Variety = "", const std::string &Scope = "") {
1726-
for (const auto *Attr : Attrs) {
1723+
// Emits the list of spellings for attributes.
1724+
void EmitClangAttrSpellingList(RecordKeeper &Records, raw_ostream &OS) {
1725+
emitSourceFileHeader("llvm::StringSwitch code to match attributes based on "
1726+
"the target triple, T", OS);
1727+
1728+
std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
1729+
1730+
for (auto I : Attrs) {
1731+
Record &Attr = *I;
1732+
17271733
// It is assumed that there will be an llvm::Triple object named T within
17281734
// scope that can be used to determine whether the attribute exists in
17291735
// a given target.
17301736
std::string Test;
1731-
if (Attr->isSubClassOf("TargetSpecificAttr")) {
1732-
const Record *R = Attr->getValueAsDef("Target");
1737+
if (Attr.isSubClassOf("TargetSpecificAttr")) {
1738+
const Record *R = Attr.getValueAsDef("Target");
17331739
std::vector<std::string> Arches = R->getValueAsListOfStrings("Arches");
17341740

17351741
Test += "(";
@@ -1754,79 +1760,13 @@ static void GenerateHasAttrSpellingStringSwitch(
17541760
}
17551761
Test += ")";
17561762
}
1757-
1758-
// If this is the C++11 variety, also add in the LangOpts test.
1759-
if (Variety == "CXX11")
1760-
Test += " && LangOpts.CPlusPlus11";
1761-
} else if (Variety == "CXX11")
1762-
// C++11 mode should be checked against LangOpts, which is presumed to be
1763-
// present in the caller.
1764-
Test = "LangOpts.CPlusPlus11";
1765-
else
1763+
} else
17661764
Test = "true";
17671765

1768-
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(*Attr);
1766+
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(Attr);
17691767
for (const auto &S : Spellings)
1770-
if (Variety.empty() || (Variety == S.variety() &&
1771-
(Scope.empty() || Scope == S.nameSpace())))
1772-
OS << " .Case(\"" << S.name() << "\", " << Test << ")\n";
1773-
}
1774-
OS << " .Default(false);\n";
1775-
}
1776-
1777-
// Emits the list of spellings for attributes.
1778-
void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
1779-
emitSourceFileHeader("Code to implement the __has_attribute logic", OS);
1780-
1781-
// Separate all of the attributes out into four group: generic, C++11, GNU,
1782-
// and declspecs. Then generate a big switch statement for each of them.
1783-
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
1784-
std::vector<Record *> Declspec, GNU;
1785-
std::map<std::string, std::vector<Record *>> CXX;
1786-
1787-
// Walk over the list of all attributes, and split them out based on the
1788-
// spelling variety.
1789-
for (auto *R : Attrs) {
1790-
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(*R);
1791-
for (const auto &SI : Spellings) {
1792-
std::string Variety = SI.variety();
1793-
if (Variety == "GNU")
1794-
GNU.push_back(R);
1795-
else if (Variety == "Declspec")
1796-
Declspec.push_back(R);
1797-
else if (Variety == "CXX11") {
1798-
CXX[SI.nameSpace()].push_back(R);
1799-
}
1800-
}
1801-
}
1802-
1803-
OS << "switch (Syntax) {\n";
1804-
OS << "case AttrSyntax::Generic:\n";
1805-
OS << " return llvm::StringSwitch<bool>(Name)\n";
1806-
GenerateHasAttrSpellingStringSwitch(Attrs, OS);
1807-
OS << "case AttrSyntax::GNU:\n";
1808-
OS << " return llvm::StringSwitch<bool>(Name)\n";
1809-
GenerateHasAttrSpellingStringSwitch(GNU, OS, "GNU");
1810-
OS << "case AttrSyntax::Declspec:\n";
1811-
OS << " return llvm::StringSwitch<bool>(Name)\n";
1812-
GenerateHasAttrSpellingStringSwitch(Declspec, OS, "Declspec");
1813-
OS << "case AttrSyntax::CXX: {\n";
1814-
// C++11-style attributes are further split out based on the Scope.
1815-
for (std::map<std::string, std::vector<Record *>>::iterator I = CXX.begin(),
1816-
E = CXX.end();
1817-
I != E; ++I) {
1818-
if (I != CXX.begin())
1819-
OS << " else ";
1820-
if (I->first.empty())
1821-
OS << "if (!Scope || Scope->getName() == \"\") {\n";
1822-
else
1823-
OS << "if (Scope->getName() == \"" << I->first << "\") {\n";
1824-
OS << " return llvm::StringSwitch<bool>(Name)\n";
1825-
GenerateHasAttrSpellingStringSwitch(I->second, OS, "CXX11", I->first);
1826-
OS << "}";
1768+
OS << ".Case(\"" << S.name() << "\", " << Test << ")\n";
18271769
}
1828-
OS << "\n}\n";
1829-
OS << "}\n";
18301770
}
18311771

18321772
void EmitClangAttrSpellingListIndex(RecordKeeper &Records, raw_ostream &OS) {

utils/TableGen/TableGen.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum ActionType {
2929
GenClangAttrList,
3030
GenClangAttrPCHRead,
3131
GenClangAttrPCHWrite,
32-
GenClangAttrHasAttributeImpl,
32+
GenClangAttrSpellingList,
3333
GenClangAttrSpellingListIndex,
3434
GenClangAttrASTVisitor,
3535
GenClangAttrTemplateInstantiate,
@@ -72,8 +72,7 @@ cl::opt<ActionType> Action(
7272
"Generate clang PCH attribute reader"),
7373
clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
7474
"Generate clang PCH attribute writer"),
75-
clEnumValN(GenClangAttrHasAttributeImpl,
76-
"gen-clang-attr-has-attribute-impl",
75+
clEnumValN(GenClangAttrSpellingList, "gen-clang-attr-spelling-list",
7776
"Generate a clang attribute spelling list"),
7877
clEnumValN(GenClangAttrSpellingListIndex,
7978
"gen-clang-attr-spelling-index",
@@ -160,8 +159,8 @@ bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
160159
case GenClangAttrPCHWrite:
161160
EmitClangAttrPCHWrite(Records, OS);
162161
break;
163-
case GenClangAttrHasAttributeImpl:
164-
EmitClangAttrHasAttrImpl(Records, OS);
162+
case GenClangAttrSpellingList:
163+
EmitClangAttrSpellingList(Records, OS);
165164
break;
166165
case GenClangAttrSpellingListIndex:
167166
EmitClangAttrSpellingListIndex(Records, OS);

utils/TableGen/TableGenBackends.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS);
3535
void EmitClangAttrList(RecordKeeper &Records, raw_ostream &OS);
3636
void EmitClangAttrPCHRead(RecordKeeper &Records, raw_ostream &OS);
3737
void EmitClangAttrPCHWrite(RecordKeeper &Records, raw_ostream &OS);
38-
void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS);
38+
void EmitClangAttrSpellingList(RecordKeeper &Records, raw_ostream &OS);
3939
void EmitClangAttrSpellingListIndex(RecordKeeper &Records, raw_ostream &OS);
4040
void EmitClangAttrASTVisitor(RecordKeeper &Records, raw_ostream &OS);
4141
void EmitClangAttrTemplateInstantiate(RecordKeeper &Records, raw_ostream &OS);

0 commit comments

Comments
 (0)