Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -2508,12 +2508,15 @@ const llvm::StringMap &CallerMap, const llvm::StringMap &CalleeMap, QualType Ty, StringRef Feature, - bool IsArgument) { + bool IsArgument, bool EnableWarning) { bool CallerHasFeat = CallerMap.lookup(Feature); bool CalleeHasFeat = CalleeMap.lookup(Feature); - if (!CallerHasFeat && !CalleeHasFeat) + if (!CallerHasFeat && !CalleeHasFeat) { + if (!EnableWarning) + 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) @@ -2530,14 +2533,20 @@ const llvm::StringMap &CallerMap, const llvm::StringMap &CalleeMap, QualType Ty, bool IsArgument) { + // Note: Darwin x86_64 targets a baseline CPU which doesn't enable + // AVX/AVX512, so it allows passing wide vectors in SSE: don't warn. + // Darwin users who do enable AVX/AVX512 are responsible for ensuring safe + // usage of wide vector types. + // However, x86_64h does enable AVX by default in all functions. + bool EnableWarning = !Ctx.getTargetInfo().getTriple().isOSDarwin(); uint64_t Size = Ctx.getTypeSize(Ty); if (Size > 256) return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, - "avx512f", IsArgument); + "avx512f", IsArgument, EnableWarning); if (Size > 128) return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx", - IsArgument); + IsArgument, EnableWarning); 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. Index: clang/test/CodeGen/target-builtin-error-3.c =================================================================== --- clang/test/CodeGen/target-builtin-error-3.c +++ clang/test/CodeGen/target-builtin-error-3.c @@ -24,6 +24,5 @@ } void avx_test( uint16_t *destData, float16 argbF) { - // expected-warning@+1{{AVX vector argument of type 'float16' (vector of 16 'float' values) without 'avx512f' enabled changes the ABI}} ((half16U *)destData)[0] = convert_half(argbF); }