Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ def err_cc1_unbounded_vscale_min : Error<

def err_drv_using_omit_rtti_component_without_no_rtti : Error<
"-fexperimental-omit-vtable-rtti call only be used with -fno-rtti">;
def warn_drv_exception_without_rtti : Warning<
"using exceptions without RTTI is not recommended">,
InGroup<DiagGroup<"exception-without-rtti">>;

def err_drv_ssp_missing_offset_argument : Error<
"'%0' is used without '-mstack-protector-guard-offset', and there is no default">;
Expand Down
13 changes: 11 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7076,9 +7076,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,

ToolChain::RTTIMode RTTIMode = TC.getRTTIMode();

if (KernelOrKext || (types::isCXX(InputType) &&
(RTTIMode == ToolChain::RM_Disabled)))
if (KernelOrKext ||
(types::isCXX(InputType) && (RTTIMode == ToolChain::RM_Disabled))) {
CmdArgs.push_back("-fno-rtti");
RTTIMode = ToolChain::RM_Disabled;
} else {
RTTIMode = ToolChain::RM_Enabled;
}

// -fshort-enums=0 is default for all architectures except Hexagon and z/OS.
if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums,
Expand Down Expand Up @@ -7331,6 +7335,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (!C.getDriver().IsCLMode())
EH = addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);

// Warn if exceptions are enabled without enabling RTTI on Darwin as the
// configuration is known to cause runtime issues in some cases.
if (RawTriple.isOSDarwin() && EH && RTTIMode == ToolChain::RM_Disabled)
D.Diag(diag::warn_drv_exception_without_rtti);

// Handle exception personalities
Arg *A = Args.getLastArg(
options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/exception-no-rtti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang -x c++ -### -c -target arm64-apple-ios -fno-rtti %s 2>&1 | FileCheck -check-prefix=WARN %s
// RUN: %clang -x c++ -### -c -target x86_64-apple-macosx -fno-rtti %s 2>&1 | FileCheck -check-prefix=WARN %s
// RUN: %clang -x c++ -### -c -target arm64-apple-ios %s 2>&1 | FileCheck -check-prefix=OK %s
// RUN: %clang -x c++ -### -c -target x86_64-apple-macosx %s 2>&1 | FileCheck -check-prefix=OK %s
// RUN: %clang -x c++ -### -c -target x86_64-linux-gnu -fexceptions -fno-rtti %s 2>&1 | FileCheck -check-prefix=OK %s
// RUN: %clang -x c++ -### -c -target x86_64-pc-windows -fexceptions -fno-rtti %s 2>&1 | FileCheck -check-prefix=OK %s

// WARN: warning: using exceptions without RTTI is not recommended
// OK-NOT: {{warning:|error:}}
Loading