[libcxx-commits] [libcxx] 44cc78d - [libc++] Fix incorrect usage of __STDC_HOSTED__

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 2 09:27:03 PDT 2020


Author: hyd-dev
Date: 2020-09-02T12:26:37-04:00
New Revision: 44cc78da056fbda2693f0489275f8e0ff1f590a1

URL: https://github.com/llvm/llvm-project/commit/44cc78da056fbda2693f0489275f8e0ff1f590a1
DIFF: https://github.com/llvm/llvm-project/commit/44cc78da056fbda2693f0489275f8e0ff1f590a1.diff

LOG: [libc++] Fix incorrect usage of __STDC_HOSTED__

D56913 introduced the _LIBCPP_FREESTANDING macro and guarded its
definition by:

	#ifndef __STDC_HOSTED__
	#  define _LIBCPP_FREESTANDING
	#endif

However, __STDC_HOSTED__ is defined as 0 in freestanding implementations
instead of undefined, which means that _LIBCPP_FREESTANDING would never
get defined. This patch corrects the above as:

	#if __STDC_HOSTED__ == 0
	#  define _LIBCPP_FREESTANDING
	#endif

Differential Revision: https://reviews.llvm.org/D86055

Added: 
    libcxx/test/libcxx/libcpp_freestanding.sh.cpp

Modified: 
    libcxx/include/__config

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index d7b6a2acaeff..3e64694f284b 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -38,7 +38,7 @@
 #  define _LIBCPP_ABI_VERSION 1
 #endif
 
-#ifndef __STDC_HOSTED__
+#if __STDC_HOSTED__ == 0
 #  define _LIBCPP_FREESTANDING
 #endif
 

diff  --git a/libcxx/test/libcxx/libcpp_freestanding.sh.cpp b/libcxx/test/libcxx/libcpp_freestanding.sh.cpp
new file mode 100644
index 000000000000..5a51f1be4e82
--- /dev/null
+++ b/libcxx/test/libcxx/libcpp_freestanding.sh.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Test that _LIBCPP_FREESTANDING is not defined when -ffreestanding is not passed
+// to the compiler but defined when -ffreestanding is passed to the compiler.
+
+// RUN: %{cxx} %{flags} %{compile_flags} -fsyntax-only %s
+// RUN: %{cxx} %{flags} %{compile_flags} -fsyntax-only -ffreestanding -DFREESTANDING %s
+
+#include <__config>
+
+#if defined(FREESTANDING) != defined(_LIBCPP_FREESTANDING)
+#error _LIBCPP_FREESTANDING should be defined in freestanding mode and not \
+       defined in non-freestanding mode
+#endif


        


More information about the libcxx-commits mailing list