Skip to content

Commit 2711e16

Browse files
[sanitizers] Use covering ObjectFormatType switches
Summary: This patch removes the `default` case from some switches on `llvm::Triple::ObjectFormatType`, and cases for the missing enumerators (`UnknownObjectFormat`, `Wasm`, and `XCOFF`) are then added. For `UnknownObjectFormat`, the effect of the action for the `default` case is maintained; otherwise, where `llvm_unreachable` is called, `report_fatal_error` is used instead. Where the `default` case returns a default value, `report_fatal_error` is used for XCOFF as a placeholder. For `Wasm`, the effect of the action for the `default` case in maintained. The code is structured to avoid strongly implying that the `Wasm` case is present for any reason other than to make the switch cover all `ObjectFormatType` enumerator values. Reviewers: sfertile, jasonliu, daltenty Reviewed By: sfertile Subscribers: hiraditya, aheejin, sunfish, llvm-commits, cfe-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D64222 llvm-svn: 366544
1 parent 7d06fff commit 2711e16

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/CodeGen/BackendUtil.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,13 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
231231
return true;
232232
case Triple::ELF:
233233
return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
234-
default:
235-
return false;
234+
case Triple::XCOFF:
235+
llvm::report_fatal_error("ASan not implemented for XCOFF.");
236+
case Triple::Wasm:
237+
case Triple::UnknownObjectFormat:
238+
break;
236239
}
240+
return false;
237241
}
238242

239243
static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,12 @@ StringRef ModuleAddressSanitizer::getGlobalMetadataSection() const {
19191919
case Triple::COFF: return ".ASAN$GL";
19201920
case Triple::ELF: return "asan_globals";
19211921
case Triple::MachO: return "__DATA,__asan_globals,regular";
1922-
default: break;
1922+
case Triple::Wasm:
1923+
case Triple::XCOFF:
1924+
report_fatal_error(
1925+
"ModuleAddressSanitizer not implemented for object file format.");
1926+
case Triple::UnknownObjectFormat:
1927+
break;
19231928
}
19241929
llvm_unreachable("unsupported object format");
19251930
}

0 commit comments

Comments
 (0)