LLVM use of C++ exceptions and RTTI

Hi,

It's good that llvm/lib builds with exceptions and RTTI disabled as it
supports doing optimization and codegen on very constrained platforms.
Judging by REQUIRES_EH in makefiles, only a few bits like TableGen, llvm-ar
and llvm-ranlib need them, and I doubt these would need to run on a target.
It's unlikely exceptions would get in in a random patch, because it would
have to change the makefile; but even so, it would be useful to know that
it's due to a definite design rule (assuming that's the case).
Maybe this could be added to http://llvm.org/docs/CodingStandards.html ?

Al

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Hi Al,

It's good that llvm/lib builds with exceptions and RTTI disabled as it
supports doing optimization and codegen on very constrained platforms.
Judging by REQUIRES_EH in makefiles, only a few bits like TableGen, llvm-ar
and llvm-ranlib need them, and I doubt these would need to run on a target.
It's unlikely exceptions would get in in a random patch, because it would
have to change the makefile; but even so, it would be useful to know that
it's due to a definite design rule (assuming that's the case).
Maybe this could be added to LLVM Coding Standards — LLVM 18.0.0git documentation ?

yes, it's a definite design rule. Can you please send a doc patch for
CodingStandards with some appropriate text in it.

Thanks a lot,

Duncan.

In that case, RTTI and exception should also be disabled from CMake
generated projects right?
Currently they are enabled all over my MSVC projects.

Hi Francois,

In that case, RTTI and exception should also be disabled from CMake
generated projects right?
Currently they are enabled all over my MSVC projects.

I'm not sure what you are asking. The goal is for LLVM to not require
RTTI or exception handling. Thus these can be disabled by the build
system (by specifying -fno-rtti etc), since they won't be used anyway.
Not disabling them won't break anything however.

Ciao,

Duncan.

I am saying that if the makefile build system disables RTTI and
exception handling the CMake build system should also disable them.
3 reasons:
- To be consistent with the makefile build
- It will generate a compile error if someone who is not aware of the
rules try to use RTTI or exceptions.
- Surely there will be a small code size gain after disabling RTTI.
(let's me measure it)

I am not a CMake expert (hello Oscar!), but if nobody fix it. I'll try
to do it myself.

+1 for not allowing exception in LLVM and clang. I never liked exceptions.

Francois Pichet <pichet2000@gmail.com> writes:

I am saying that if the makefile build system disables RTTI and
exception handling the CMake build system should also disable them.
3 reasons:
- To be consistent with the makefile build
- It will generate a compile error if someone who is not aware of the
rules try to use RTTI or exceptions.
- Surely there will be a small code size gain after disabling RTTI.
(let's me measure it)

I am not a CMake expert (hello Oscar!), but if nobody fix it. I'll try
to do it myself.

If you don't see a commit resolving this on the next 24 hours, go ahead.

(Implementing the feature is a few minutes. Testing requires more time.)

[snip]

Francois Pichet <pichet2000@gmail.com> writes:

[snip]

I am not a CMake expert (hello Oscar!), but if nobody fix it. I'll try
to do it myself.

Disabling EH on MSVC creates warnings coming from system files
(xlocale). I'm reluctant to commit the patch until the consequences are
analyzed.

index a71c6f2..deca699 100644
--- a/cmake/modules/LLVMProcessSources.cmake
+++ b/cmake/modules/LLVMProcessSources.cmake
@@ -41,11 +41,15 @@ function(llvm_process_sources OUT_VAR)
   if( NOT LLVM_REQUIRES_EH )
     if( CMAKE_COMPILER_IS_GNUCXX )
       add_definitions( -fno-exceptions )
+ elseif( MSVC )
+ add_definitions( /EHs-c- )
     endif()
   endif()
   if( NOT LLVM_REQUIRES_RTTI )
     if( CMAKE_COMPILER_IS_GNUCXX )
       add_definitions( -fno-rtti )
+ elseif( MSVC )
+ add_definitions( /GR- )
     endif()
   endif()