[llvm] r365118 - [Remarks] Silence gcc warning by catching unhandled values in switches
Mikael Holmen via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 4 02:29:18 PDT 2019
Author: uabelho
Date: Thu Jul 4 02:29:18 2019
New Revision: 365118
URL: http://llvm.org/viewvc/llvm-project?rev=365118&view=rev
Log:
[Remarks] Silence gcc warning by catching unhandled values in switches
Without this fix gcc (7.4) complains with
../lib/Remarks/RemarkParser.cpp: In function 'std::unique_ptr<llvm::remarks::ParserImpl> formatToParserImpl(llvm::remarks::ParserFormat, llvm::StringRef)':
../lib/Remarks/RemarkParser.cpp:29:1: error: control reaches end of non-void function [-Werror=return-type]
}
^
../lib/Remarks/RemarkParser.cpp: In function 'std::unique_ptr<llvm::remarks::ParserImpl> formatToParserImpl(llvm::remarks::ParserFormat, llvm::StringRef, const llvm::remarks::ParsedStringTable&)':
../lib/Remarks/RemarkParser.cpp:38:1: error: control reaches end of non-void function [-Werror=return-type]
}
^
The Format enum currently only contains the value YAML which is indeed
already handled in the switches, but gcc complains anyway.
Adding a default case with an llvm_unreachable silences gcc.
Modified:
llvm/trunk/lib/Remarks/RemarkParser.cpp
Modified: llvm/trunk/lib/Remarks/RemarkParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/RemarkParser.cpp?rev=365118&r1=365117&r2=365118&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/RemarkParser.cpp (original)
+++ llvm/trunk/lib/Remarks/RemarkParser.cpp Thu Jul 4 02:29:18 2019
@@ -25,6 +25,8 @@ static std::unique_ptr<ParserImpl> forma
switch (Format) {
case ParserFormat::YAML:
return llvm::make_unique<YAMLParserImpl>(Buf);
+ default:
+ llvm_unreachable("Unknown format encountered!");
};
}
@@ -34,6 +36,8 @@ formatToParserImpl(ParserFormat Format,
switch (Format) {
case ParserFormat::YAML:
return llvm::make_unique<YAMLParserImpl>(Buf, &StrTab);
+ default:
+ llvm_unreachable("Unknown format encountered!");
};
}
More information about the llvm-commits
mailing list