[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 28 20:06:51 PDT 2018


EricWF created this revision.
EricWF added reviewers: rsmith, vsapsai, erik.pilkington, ahatanak.

Libc++ needs to know when aligned allocation is supported by clang, but is otherwise unavailable at link time. This patch adds a predefined macro to allow libc++ to do that.

IDK if using a predefined macro is the best approach. Better approaches are always welcome :-)

Also see llvm.org/PR22634


Repository:
  rC Clang

https://reviews.llvm.org/D45015

Files:
  lib/Frontend/InitPreprocessor.cpp
  test/Preprocessor/predefined-macros.c


Index: test/Preprocessor/predefined-macros.c
===================================================================
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -271,3 +271,20 @@
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
 // CHECK-SPIR: #define __IMAGE_SUPPORT__ 1
+
+
+// RUN: %clang_cc1 %s -x c++ -E -dM  -faligned-allocation \
+// RUN: | FileCheck  %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM  -std=c++17 \
+// RUN: | FileCheck %s -check-prefix=CHECK-ALIGNED-ALLOC-AVAILABLE
+
+// CHECK-ALIGNED-ALLOC-AVAILABLE-NOT: __ALIGNED_ALLOCATION_UNAVAILABLE__
+
+// RUN: %clang_cc1 %s -x c++ -E -dM -std=c++03  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+// RUN: %clang_cc1 %s -x c++ -E -dM -faligned-allocation -faligned-alloc-unavailable  \
+// RUN: | FileCheck %s -match-full-lines -check-prefix=CHECK-ALIGNED-ALLOC-UNAVAILABLE
+
+// CHECK-ALIGNED-ALLOC-UNAVAILABLE: #define __ALIGNED_ALLOCATION_UNAVAILABLE__ 1
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -1056,6 +1056,9 @@
     Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
   }
 
+  if (!LangOpts.AlignedAllocation || LangOpts.AlignedAllocationUnavailable)
+    Builder.defineMacro("__ALIGNED_ALLOCATION_UNAVAILABLE__");
+
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45015.140181.patch
Type: text/x-patch
Size: 1789 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180329/8d92c7f0/attachment.bin>


More information about the cfe-commits mailing list