[libc-commits] [libc] 573ade4 - [libc][WrapperGen] Replace the C _Noreturn annotation with C++ [[noreturn]].

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Fri Nov 6 11:38:02 PST 2020


Author: Siva Chandra Reddy
Date: 2020-11-06T11:37:48-08:00
New Revision: 573ade4bef005a36dc02f2df0b3fcb57ef7b6a72

URL: https://github.com/llvm/llvm-project/commit/573ade4bef005a36dc02f2df0b3fcb57ef7b6a72
DIFF: https://github.com/llvm/llvm-project/commit/573ade4bef005a36dc02f2df0b3fcb57ef7b6a72.diff

LOG: [libc][WrapperGen] Replace the C _Noreturn annotation with C++ [[noreturn]].

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D90900

Added: 
    

Modified: 
    libc/utils/tools/WrapperGen/Main.cpp

Removed: 
    


################################################################################
diff  --git a/libc/utils/tools/WrapperGen/Main.cpp b/libc/utils/tools/WrapperGen/Main.cpp
index 0b064bcbb814..37457598cb7c 100644
--- a/libc/utils/tools/WrapperGen/Main.cpp
+++ b/libc/utils/tools/WrapperGen/Main.cpp
@@ -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;
@@ -73,8 +83,8 @@ static bool WrapperGenMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
   // match the standard types. Either handle such 
diff erences 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;


        


More information about the libc-commits mailing list