@@ -3946,20 +3946,24 @@ const char *DefaultFallbackStyle = "LLVM";
3946
3946
3947
3947
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
3948
3948
loadAndParseConfigFile (StringRef ConfigFile, llvm::vfs::FileSystem *FS,
3949
- FormatStyle *Style, bool AllowUnknownOptions) {
3949
+ FormatStyle *Style, bool AllowUnknownOptions,
3950
+ llvm::SourceMgr::DiagHandlerTy DiagHandler) {
3950
3951
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
3951
3952
FS->getBufferForFile (ConfigFile.str ());
3952
3953
if (auto EC = Text.getError ())
3953
3954
return EC;
3954
- if (auto EC = parseConfiguration (*Text.get (), Style, AllowUnknownOptions))
3955
+ if (auto EC = parseConfiguration (*Text.get (), Style, AllowUnknownOptions,
3956
+ DiagHandler)) {
3955
3957
return EC;
3958
+ }
3956
3959
return Text;
3957
3960
}
3958
3961
3959
3962
Expected<FormatStyle> getStyle (StringRef StyleName, StringRef FileName,
3960
3963
StringRef FallbackStyleName, StringRef Code,
3961
3964
llvm::vfs::FileSystem *FS,
3962
- bool AllowUnknownOptions) {
3965
+ bool AllowUnknownOptions,
3966
+ llvm::SourceMgr::DiagHandlerTy DiagHandler) {
3963
3967
FormatStyle Style = getLLVMStyle (guessLanguage (FileName, Code));
3964
3968
FormatStyle FallbackStyle = getNoStyle ();
3965
3969
if (!getPredefinedStyle (FallbackStyleName, Style.Language , &FallbackStyle))
@@ -3972,7 +3976,7 @@ Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
3972
3976
StringRef Source = " <command-line>" ;
3973
3977
if (std::error_code ec =
3974
3978
parseConfiguration (llvm::MemoryBufferRef (StyleName, Source), &Style,
3975
- AllowUnknownOptions)) {
3979
+ AllowUnknownOptions, DiagHandler )) {
3976
3980
return make_string_error (" Error parsing -style: " + ec.message ());
3977
3981
}
3978
3982
@@ -3992,7 +3996,8 @@ Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
3992
3996
StyleName.starts_with_insensitive (" file:" )) {
3993
3997
auto ConfigFile = StyleName.substr (5 );
3994
3998
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
3995
- loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions);
3999
+ loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions,
4000
+ DiagHandler);
3996
4001
if (auto EC = Text.getError ()) {
3997
4002
return make_string_error (" Error reading " + ConfigFile + " : " +
3998
4003
EC.message ());
@@ -4031,8 +4036,9 @@ Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
4031
4036
4032
4037
auto applyChildFormatTexts = [&](FormatStyle *Style) {
4033
4038
for (const auto &MemBuf : llvm::reverse (ChildFormatTextToApply)) {
4034
- auto EC = parseConfiguration (*MemBuf, Style, AllowUnknownOptions,
4035
- dropDiagnosticHandler);
4039
+ auto EC =
4040
+ parseConfiguration (*MemBuf, Style, AllowUnknownOptions,
4041
+ DiagHandler ? DiagHandler : dropDiagnosticHandler);
4036
4042
// It was already correctly parsed.
4037
4043
assert (!EC);
4038
4044
static_cast <void >(EC);
@@ -4066,7 +4072,8 @@ Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
4066
4072
}
4067
4073
4068
4074
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
4069
- loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions);
4075
+ loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions,
4076
+ DiagHandler);
4070
4077
if (auto EC = Text.getError ()) {
4071
4078
if (EC != ParseError::Unsuitable) {
4072
4079
return make_string_error (" Error reading " + ConfigFile + " : " +
0 commit comments