Skip to content

Commit

Permalink
[libc][WrapperGen] Replace the C _Noreturn annotation with C++ [[nore…
Browse files Browse the repository at this point in the history
…turn]].

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D90900
  • Loading branch information
Siva Chandra Reddy committed Nov 6, 2020
1 parent 85f4be0 commit 573ade4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libc/utils/tools/WrapperGen/Main.cpp
Expand Up @@ -38,8 +38,18 @@ static bool WrapperGenMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
llvm::Record *FunctionSpec = NameSpecPair.second;
llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
OS << "extern \"C\" " << Indexer.getTypeAsString(ReturnType) << " "
<< FunctionName << "(";
std::string ReturnTypeString = Indexer.getTypeAsString(ReturnType);
bool ShouldReturn = true;
// We are generating C wrappers in C++ code. So, we should convert the C
// _Noreturn to the C++ [[noreturn]].
llvm::StringRef NR("_Noreturn "); // Note the space after _Noreturn
llvm::StringRef RT(ReturnTypeString);
if (RT.startswith(NR)) {
RT = RT.drop_front(NR.size() - 1); // - 1 because of the space.
ReturnTypeString = std::string("[[noreturn]]") + std::string(RT);
ShouldReturn = false;
}
OS << "extern \"C\" " << ReturnTypeString << " " << FunctionName << "(";

auto ArgsList = FunctionSpec->getValueAsListOfDefs("Args");
std::stringstream CallArgs;
Expand Down Expand Up @@ -73,8 +83,8 @@ static bool WrapperGenMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
// match the standard types. Either handle such differences here, or
// avoid such a thing in the implementations.
OS << ") {\n"
<< " return __llvm_libc::" << FunctionName << "(" << CallArgs.str()
<< ");\n"
<< " " << (ShouldReturn ? "return " : "")
<< "__llvm_libc::" << FunctionName << "(" << CallArgs.str() << ");\n"
<< "}\n";

return false;
Expand Down

0 comments on commit 573ade4

Please sign in to comment.