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);
 }


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);
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to