Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -2508,12 +2508,17 @@ const llvm::StringMap &CallerMap, const llvm::StringMap &CalleeMap, QualType Ty, StringRef Feature, - bool IsArgument) { + bool IsArgument, const llvm::Triple &TT) { bool CallerHasFeat = CallerMap.lookup(Feature); bool CalleeHasFeat = CalleeMap.lookup(Feature); - if (!CallerHasFeat && !CalleeHasFeat) + if (!CallerHasFeat && !CalleeHasFeat) { + // Darwin doesn't enable AVX/AVX512 by default to support Rosetta 2, so it's + // user's responsibility to use AVX/AVX512 safely. + if (TT.isOSDarwin()) + return false; return Diag.Report(CallLoc, diag::warn_avx_calling_convention) << IsArgument << Ty << Feature; + } // Mixing calling conventions here is very clearly an error. if (!CallerHasFeat || !CalleeHasFeat) @@ -2531,13 +2536,14 @@ const llvm::StringMap &CalleeMap, QualType Ty, bool IsArgument) { uint64_t Size = Ctx.getTypeSize(Ty); + const llvm::Triple &TT = Ctx.getTargetInfo().getTriple(); if (Size > 256) return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, - "avx512f", IsArgument); + "avx512f", IsArgument, TT); if (Size > 128) return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx", - IsArgument); + IsArgument, TT); return false; } Index: clang/test/CodeGen/target-avx-abi-diag.c =================================================================== --- clang/test/CodeGen/target-avx-abi-diag.c +++ clang/test/CodeGen/target-avx-abi-diag.c @@ -1,6 +1,9 @@ -// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -verify=no256,no512 -o - -S -// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx -verify=no512 -o - -S +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -verify=no256,no512,no256-err,no512-err -o - -S +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx -verify=no512,no512-err -o - -S // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx512f -verify=both -o - -S + +// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -verify=no256-err,no512-err -o - -S +// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -target-feature +avx -verify=no512-err -o - -S // REQUIRES: x86-registered-target // both-no-diagnostics @@ -31,12 +34,12 @@ // If only 1 side has an attribute, error. void call_errors(void) { avx256Type t1; - takesAvx256(t1); // no256-error {{AVX vector argument of type 'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the ABI}} + takesAvx256(t1); // no256-err-error {{AVX vector argument of type 'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the ABI}} avx512fType t2; - takesAvx512(t2); // no512-error {{AVX vector argument of type 'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes the ABI}} + takesAvx512(t2); // no512-err-error {{AVX vector argument of type 'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes the ABI}} - variadic_err(1, t1); // no256-error {{AVX vector argument of type 'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the ABI}} - variadic_err(3, t2); // no512-error {{AVX vector argument of type 'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes the ABI}} + variadic_err(1, t1); // no256-err-error {{AVX vector argument of type 'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the ABI}} + variadic_err(3, t2); // no512-err-error {{AVX vector argument of type 'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes the ABI}} } // These two don't diagnose anything, since these are valid calls.