EricWF updated this revision to Diff 149596. EricWF edited the summary of this revision. EricWF added a comment.
Update the patch with the form suggested in the previous conversation. See the updated summary for a description of the behavior. The Darwin driver no longer passes `-faligned-alloc-unavailable` when `-nostdinc++` is specified, but I'm not sure this is the behavior we want. Having `-nostdinc++` have side-effects which affect the well-formedness of new/delete expressions seems non-obvious and potentially problematic. https://reviews.llvm.org/D45015 Files: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Driver/ToolChains/Darwin.cpp lib/Frontend/InitPreprocessor.cpp lib/Sema/SemaExprCXX.cpp test/Driver/unavailable_aligned_allocation.cpp test/Lexer/aligned-allocation.cpp
Index: test/Lexer/aligned-allocation.cpp =================================================================== --- /dev/null +++ test/Lexer/aligned-allocation.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -DEXPECT_DEFINED +// +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -faligned-alloc-unavailable +// +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -faligned-allocation -faligned-alloc-unavailable + +// Test that __cpp_aligned_new is not defined when CC1 is passed +// -faligned-alloc-unavailable by the Darwin driver, even when aligned +// allocation is actually enabled. + +// expected-no-diagnostics +#ifdef EXPECT_DEFINED +# ifndef __cpp_aligned_new +# error "__cpp_aligned_new" should be defined +# endif +#else +# ifdef __cpp_aligned_new +# error "__cpp_aligned_new" should not be defined +# endif +#endif Index: test/Driver/unavailable_aligned_allocation.cpp =================================================================== --- test/Driver/unavailable_aligned_allocation.cpp +++ test/Driver/unavailable_aligned_allocation.cpp @@ -51,4 +51,16 @@ // RUN: -c -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=AVAILABLE // +// Check that passing -faligned-allocation, -fno-aligned-allocation, or +// -nostdinc++ stops the driver from passing -faligned-alloc-unavailable to cc1. +// +// RUN: %clang -target x86_64-apple-macosx10.12 -faligned-allocation -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.12 -fno-aligned-allocation -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.12 -nostdinc++ -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE + // AVAILABLE-NOT: "-faligned-alloc-unavailable" Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -1697,7 +1697,7 @@ StringRef OSName = AvailabilityAttr::getPlatformNameSourceSpelling( S.getASTContext().getTargetInfo().getPlatformName()); - S.Diag(Loc, diag::warn_aligned_allocation_unavailable) + S.Diag(Loc, diag::err_aligned_allocation_unavailable) << IsDelete << FD.getType().getAsString() << OSName << alignedAllocMinVersion(T.getOS()).getAsString(); S.Diag(Loc, diag::note_silence_unligned_allocation_unavailable); Index: lib/Frontend/InitPreprocessor.cpp =================================================================== --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -551,7 +551,7 @@ Builder.defineMacro("__cpp_nontype_template_args", "201411"); Builder.defineMacro("__cpp_fold_expressions", "201603"); } - if (LangOpts.AlignedAllocation) + if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable) Builder.defineMacro("__cpp_aligned_new", "201606"); // TS features. Index: lib/Driver/ToolChains/Darwin.cpp =================================================================== --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -2018,7 +2018,13 @@ void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const { - if (isAlignedAllocationUnavailable()) + // Pass "-faligned-alloc-unavailable" only when the user hasn't manually + // enabled or disabled aligned allocations and hasn't specified a custom + // standard library installation. + if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation, + options::OPT_fno_aligned_allocation, + options::OPT_nostdincxx) && + isAlignedAllocationUnavailable()) CC1Args.push_back("-faligned-alloc-unavailable"); } Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -6419,12 +6419,12 @@ "type %0 requires %1 bytes of alignment and the default allocator only " "guarantees %2 bytes">, InGroup<OveralignedType>, DefaultIgnore; -def warn_aligned_allocation_unavailable :Warning< +def err_aligned_allocation_unavailable : Error< "aligned %select{allocation|deallocation}0 function of type '%1' is only " - "available on %2 %3 or newer">, InGroup<AlignedAllocationUnavailable>, DefaultError; + "available on %2 %3 or newer">; def note_silence_unligned_allocation_unavailable : Note< "if you supply your own aligned allocation functions, use " - "-Wno-aligned-allocation-unavailable to silence this diagnostic">; + "-faligned-allocation to silence this diagnostic">; def err_conditional_void_nonvoid : Error< "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand " Index: include/clang/Basic/DiagnosticGroups.td =================================================================== --- include/clang/Basic/DiagnosticGroups.td +++ include/clang/Basic/DiagnosticGroups.td @@ -352,7 +352,6 @@ def NullPointerArithmetic : DiagGroup<"null-pointer-arithmetic">; def : DiagGroup<"effc++", [NonVirtualDtor]>; def OveralignedType : DiagGroup<"over-aligned">; -def AlignedAllocationUnavailable : DiagGroup<"aligned-allocation-unavailable">; def OldStyleCast : DiagGroup<"old-style-cast">; def : DiagGroup<"old-style-definition">; def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits