Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -3347,10 +3347,12 @@ def VFork : LibBuiltin<"unistd.h"> {
}

// POSIX pthread.h
// FIXME: This should be a GNULibBuiltin, but it's currently missing the prototype.

def PthreadCreate : CustomEntry {
let Entry = "LIBBUILTIN(pthread_create, \"\", \"fC<2,3>\", PTHREAD_H, ALL_GNU_LANGUAGES)";
def PthreadCreate : GNULibBuiltin<"pthread.h"> {
let Spellings = ["pthread_create"];
let Attributes = [FunctionWithoutBuiltinPrefix, Callback<[2, 3]>];
// Note that we don't have an expressable prototype so we leave it empty.
let Prototype = "";
}

def SigSetJmp : LibBuiltin<"setjmp.h"> {
Expand Down
13 changes: 9 additions & 4 deletions clang/include/clang/Basic/BuiltinsBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class IndexedAttribute<string baseMangling, int I> : Attribute<baseMangling> {
int Index = I;
}

class MultiIndexAttribute<string baseMangling, list<int> Is>
: Attribute<baseMangling> {
list<int> Indices = Is;
}

// Standard Attributes
// -------------------
def NoReturn : Attribute<"r">;
Expand Down Expand Up @@ -77,6 +82,10 @@ def Constexpr : Attribute<"E">;
// Builtin is immediate and must be constant evaluated. Implies Constexpr, and will only be supported in C++20 mode.
def Consteval : Attribute<"EG">;

// Callback behavior: the first index argument is called with the arguments
// indicated by the remaining indices.
class Callback<list<int> ArgIndices> : MultiIndexAttribute<"C", ArgIndices>;

// Builtin kinds
// =============

Expand All @@ -90,10 +99,6 @@ class Builtin {
bit RequiresUndef = 0;
}

class CustomEntry {
string Entry;
}

class AtomicBuiltin : Builtin;
class TargetBuiltin : Builtin {
string Features = "";
Expand Down
22 changes: 17 additions & 5 deletions clang/utils/TableGen/ClangBuiltinsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
Expand All @@ -37,6 +38,14 @@ class PrototypeParser {
private:
void ParsePrototype(StringRef Prototype) {
Prototype = Prototype.trim();

// Some builtins don't have an expressible prototype, simply emit an empty
// string for them.
if (Prototype.empty()) {
Type = "";
return;
}

ParseTypes(Prototype);
}

Expand Down Expand Up @@ -236,8 +245,15 @@ void PrintAttributes(const Record *Builtin, BuiltinType BT, raw_ostream &OS) {

for (const auto *Attr : Builtin->getValueAsListOfDefs("Attributes")) {
OS << Attr->getValueAsString("Mangling");
if (Attr->isSubClassOf("IndexedAttribute"))
if (Attr->isSubClassOf("IndexedAttribute")) {
OS << ':' << Attr->getValueAsInt("Index") << ':';
} else if (Attr->isSubClassOf("MultiIndexAttribute")) {
OS << '<';
llvm::ListSeparator Sep(",");
for (int64_t Index : Attr->getValueAsListOfInts("Indices"))
OS << Sep << Index;
OS << '>';
}
}
OS << '\"';
}
Expand Down Expand Up @@ -380,10 +396,6 @@ void clang::EmitClangBuiltins(const RecordKeeper &Records, raw_ostream &OS) {
EmitBuiltin(OS, Builtin);
}

for (const auto *Entry : Records.getAllDerivedDefinitions("CustomEntry")) {
OS << Entry->getValueAsString("Entry") << '\n';
}

OS << R"c++(
#undef ATOMIC_BUILTIN
#undef BUILTIN
Expand Down
Loading