<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Attempt to build memory sanitized libc++ with compiler-rt and libunwind fails"
   href="https://bugs.llvm.org/show_bug.cgi?id=51774">51774</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Attempt to build memory sanitized libc++ with compiler-rt and libunwind fails
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nehaljw.kkd1@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25235" name="attach_25235" title="BugFix in CMake logic for computing CMAKE_REQUIRED_FLAGS">attachment 25235</a> <a href="attachment.cgi?id=25235&action=edit" title="BugFix in CMake logic for computing CMAKE_REQUIRED_FLAGS">[details]</a></span>
BugFix in CMake logic for computing CMAKE_REQUIRED_FLAGS

The following configure and build commands succeed on 12.0.1:

cmake -S llvm-project/llvm/ -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind" -DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++ -DLIBCXX_USE_COMPILER_RT=ON -DLLVM_BUILD_TESTS=OFF
-DLLVM_BUILD_EXAMPLES=OFF -DLLVM_TARGETS_TO_BUILD=X86
-DLIBCXXABI_USE_LLVM_UNWINDER=ON

cmake --build build -- cxx

However, if I try to configure a memory sanitized build:

cmake -S llvm-project/llvm/ -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind" -DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++ -DLIBCXX_USE_COMPILER_RT=ON -DLLVM_BUILD_TESTS=OFF
-DLLVM_BUILD_EXAMPLES=OFF -DLLVM_TARGETS_TO_BUILD=X86
-DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLLVM_USE_SANITIZER=MemoryWithOrigins

And then try to build it:

cmake --build build -- cxx

It fails with:
In file included from
/spare/local/nehal/ossrepos/llvm-project/libcxx/src/condition_variable_destructor.cpp:15:
In file included from
/spare/local/nehal/ossrepos/build/include/c++/v1/__threading_support:15:
In file included from
/spare/local/nehal/ossrepos/build/include/c++/v1/chrono:830:
In file included from
/spare/local/nehal/ossrepos/build/include/c++/v1/ratio:81:
/spare/local/nehal/ossrepos/build/include/c++/v1/cstdint:152:8: error: no
member named 'int8_t' in the global namespace; did you mean '__int8_t'?
using::int8_t;
     ~~^~~~~~
       __int8_t

The primary reason behind this failure is the absence of the -nostdinc++ flag 
while compiling the file. And it isn't passed because of a bug in
llvm-project/libcxx/cmake/config-ix.cmake which generates incorrect value for
CMAKE_REQUIRED_FLAGS.

The diff below:

diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 894f637f814f..5d1c664f01ef 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -78,6 +78,8 @@ int main() { return 0; }
   cmake_pop_check_state()
 endif()

+message(FATAL_ERROR "${CMAKE_REQUIRED_FLAGS}")
+
 # Check libraries
 if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for
the

Outputs:

-Werror=unguarded-availability-new -nodefaultlibs;-rtlib=compiler-rt
-fno-sanitize=all

Notice the flags are two separate strings (as entries of a list), but they
should actually be a single string.

This is also backed by the fact that the configure step reports many 'support'
failures as well:
...
-- Performing Test LIBCXX_SUPPORTS_FNO_OMIT_FRAME_POINTER_FLAG
-- Performing Test LIBCXX_SUPPORTS_FNO_OMIT_FRAME_POINTER_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_GLINE_TABLES_ONLY_FLAG
-- Performing Test LIBCXX_SUPPORTS_GLINE_TABLES_ONLY_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_FALIGNED_ALLOCATION_FLAG
-- Performing Test LIBCXX_SUPPORTS_FALIGNED_ALLOCATION_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_NOSTDINCXX_FLAG
-- Performing Test LIBCXX_SUPPORTS_NOSTDINCXX_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test LIBCXX_SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_FVISIBILITY_EQ_HIDDEN_FLAG
-- Performing Test LIBCXX_SUPPORTS_FVISIBILITY_EQ_HIDDEN_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WALL_FLAG
-- Performing Test LIBCXX_SUPPORTS_WALL_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WEXTRA_FLAG
-- Performing Test LIBCXX_SUPPORTS_WEXTRA_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_W_FLAG
-- Performing Test LIBCXX_SUPPORTS_W_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WWRITE_STRINGS_FLAG
-- Performing Test LIBCXX_SUPPORTS_WWRITE_STRINGS_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_UNUSED_PARAMETER_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_UNUSED_PARAMETER_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_LONG_LONG_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_LONG_LONG_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG
-- Performing Test LIBCXX_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WEXTRA_SEMI_FLAG
-- Performing Test LIBCXX_SUPPORTS_WEXTRA_SEMI_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_USER_DEFINED_LITERALS_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_USER_DEFINED_LITERALS_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_COVERED_SWITCH_DEFAULT_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_SUGGEST_OVERRIDE_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_SUGGEST_OVERRIDE_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_IGNORED_ATTRIBUTES_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_IGNORED_ATTRIBUTES_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_WNO_ERROR_FLAG
-- Performing Test LIBCXX_SUPPORTS_WNO_ERROR_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_EHSC_FLAG
-- Performing Test LIBCXX_SUPPORTS_EHSC_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_ZL_FLAG
-- Performing Test LIBCXX_SUPPORTS_ZL_FLAG - Failed
-- Performing Test LIBCXX_SUPPORTS_NODEFAULTLIB_FLAG
-- Performing Test LIBCXX_SUPPORTS_NODEFAULTLIB_FLAG - Failed
...


The attached patch fixes the reported issue.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>