diff --git a/libc/utils/tools/WrapperGen/Main.cpp b/libc/utils/tools/WrapperGen/Main.cpp --- a/libc/utils/tools/WrapperGen/Main.cpp +++ b/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;