Skip to content

[cmake] Add options for enabling Clang sanitizers - #2832

Merged
antiagainst merged 5 commits into
iree-org:mainfrom
antiagainst:cmake-sanitizers
Sep 8, 2020
Merged

antiagainst merged 5 commits into
iree-org:mainfrom
antiagainst:cmake-sanitizers

Conversation

@antiagainst

Copy link
Copy Markdown
Member

No description provided.

Comment thread build_tools/cmake/iree_copts.cmake Resolved
Comment thread build_tools/cmake/iree_copts.cmake Resolved
Comment thread CMakeLists.txt Outdated
option(IREE_ENABLE_LLD "Use lld when linking" OFF)

string(JOIN " " CMAKE_CXX_FLAGS ${IREE_DEFAULT_COPTS})
string(JOIN " " IREE_DEFAULT_COPTS_STR ${IREE_DEFAULT_COPTS})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this? we don't want to do string manipulation like this as it breaks flags with spaces in them - COPTS is a list (; separated) and should only be manipulated with list()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked from existing code. :) But is CMAKE_CXX_FLAGS a list? The cases what I've seen thus far they are all manipulated as a string.. (Which is ugly for sure.) I remembered that treating it with list(APPEND seeing errors. Let me do a double check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating it as list generates compilation command like /usr/bin/clang++ ... -fdiagnostics-color -g;-fsanitize=address and errors out..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be treating lists as lists... fighting with CMake like this leads to cross-platform issues and pain :/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed. But I think the problem is that CMAKE_CXX_FLAGS is treated as a single string instead of a list by CMake when given to the compiler: https://stackoverflow.com/questions/16433391/cmake-list-append-for-compiler-flags-yields-bogus-results. I converted where I can in iree_copts.cmake, but here still we need to concatenate to make a single string. Unless I miss something or another approach to handle this..

Comment thread build_tools/cmake/iree_copts.cmake Resolved
Comment thread CMakeLists.txt Outdated
option(IREE_ENABLE_LLD "Use lld when linking" OFF)

string(JOIN " " CMAKE_CXX_FLAGS ${IREE_DEFAULT_COPTS})
string(JOIN " " IREE_DEFAULT_COPTS_STR ${IREE_DEFAULT_COPTS})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be treating lists as lists... fighting with CMake like this leads to cross-platform issues and pain :/

@antiagainst
antiagainst merged commit d87ecb7 into iree-org:main Sep 8, 2020
@antiagainst
antiagainst deleted the cmake-sanitizers branch September 8, 2020 17:21
@ScottTodd ScottTodd mentioned this pull request Sep 8, 2020
stellaraccident added a commit that referenced this pull request Sep 10, 2020
This reverts commit d87ecb7.

This change overwrites the CMAKE_CXX_FLAGS_DEBUG variable for debug builds, even when sanitizers are not enabled, making it impossible to have a debug build.
antiagainst added a commit to antiagainst/iree that referenced this pull request Sep 10, 2020
@hanhanW hanhanW mentioned this pull request Sep 10, 2020
antiagainst added a commit that referenced this pull request Sep 10, 2020
* [cmake] Add options for enabling Clang sanitizers (#2832)

* Fix C/C++ Flags appending
@hanhanW hanhanW mentioned this pull request Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants