[libc-commits] [PATCH] D90900: [libc][WrapperGen] Replace the C _Noreturn annotation with C++ [[noreturn]].
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Fri Nov 6 11:37:21 PST 2020
sivachandra updated this revision to Diff 303509.
sivachandra added a comment.
Fix typo.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90900/new/
https://reviews.llvm.org/D90900
Files:
libc/utils/tools/WrapperGen/Main.cpp
Index: libc/utils/tools/WrapperGen/Main.cpp
===================================================================
--- libc/utils/tools/WrapperGen/Main.cpp
+++ libc/utils/tools/WrapperGen/Main.cpp
@@ -38,8 +38,18 @@
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;
@@ -73,8 +83,8 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90900.303509.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20201106/8395c2c1/attachment.bin>
More information about the libc-commits
mailing list