Skip to content

Commit fa39b39

Browse files
authored
Replace dynamic_cast with virtual call (microsoft#6515)
Make TextDiagnosticPrinter::setPrefix a virtual function in base class DiagnosticConsumer. This allows us to avoid using dynamic_cast in BackendConsumer::DxilDiagHandler, required for codebases that do not enable RTTI. This is also the only place in the codebase that uses RTTI (AFAICT).
1 parent 422a60e commit fa39b39

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

tools/clang/include/clang/Basic/Diagnostic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,8 @@ class DiagnosticConsumer {
13951395
/// warnings and errors.
13961396
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
13971397
const Diagnostic &Info);
1398+
1399+
virtual void setPrefix(std::string Value) {} // HLSL Change
13981400
};
13991401

14001402
/// \brief A diagnostic client that ignores all diagnostics.

tools/clang/include/clang/Frontend/TextDiagnosticPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class TextDiagnosticPrinter : public DiagnosticConsumer {
4545
/// setPrefix - Set the diagnostic printer prefix string, which will be
4646
/// printed at the start of any diagnostics. If empty, no prefix string is
4747
/// used.
48-
void setPrefix(std::string Value) { Prefix = Value; }
48+
// HLSL Change: add override
49+
void setPrefix(std::string Value) override { Prefix = Value; }
4950

5051
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
5152
void EndSourceFile() override;

tools/clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ BackendConsumer::DxilDiagHandler(const llvm::DiagnosticInfoDxil &D) {
557557

558558
// If no location information is available, add function name
559559
if (Loc.isInvalid()) {
560-
auto *DiagClient = dynamic_cast<TextDiagnosticPrinter*>(Diags.getClient());
560+
auto *DiagClient = Diags.getClient();
561561
auto *func = D.getFunction();
562562
if (DiagClient && func)
563563
DiagClient->setPrefix("Function: " + func->getName().str());

0 commit comments

Comments
 (0)