From 2440fb1f91557912f8c43cb72201170254ae09f4 Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Mon, 16 Sep 2013 18:07:35 +0000 Subject: [PATCH] Add error checking to reject neon_vector_type attribute on targets without NEON. Patch by Artyom Skrobov. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190801 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Basic/Targets.cpp | 4 +--- lib/Sema/SemaType.cpp | 6 ++++++ test/Analysis/misc-ps-arm.m | 2 +- test/CodeGen/arm-arguments.c | 4 ++-- test/CodeGen/arm-asm-diag.c | 2 +- test/CodeGen/arm-asm-warn.c | 2 +- test/CodeGen/struct-init.c | 2 +- test/CodeGen/struct-matching-constraint.c | 2 +- test/CodeGenCXX/aarch64-mangle-neon-vectors.cpp | 2 +- test/CodeGenCXX/mangle-neon-vectors.cpp | 2 +- test/Sema/aarch64-neon-vector-types.c | 2 +- test/Sema/neon-vector-types-support.c | 4 ++++ test/Sema/neon-vector-types.c | 3 ++- test/SemaCXX/neon-vector-types.cpp | 2 +- 15 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 test/Sema/neon-vector-types-support.c diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2932fe19d6..fd82f161e6 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1785,6 +1785,8 @@ def err_attribute_too_few_arguments : Error< def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">; def err_attribute_bad_neon_vector_size : Error< "Neon vector size must be 64 or 128 bits">; +def err_attribute_unsupported : Error< + "%0 attribute is not supported for this target">; def err_aligned_attribute_argument_not_int : Error< "'aligned' attribute requires integer constant">; def err_alignas_attribute_wrong_decl_type : Error< diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index b31ec78c7e..dc31ace06c 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -3711,9 +3711,7 @@ public: .Case("arm", true) .Case("softfloat", SoftFloat) .Case("thumb", IsThumb) - .Case("neon", (FPU & NeonFPU) && !SoftFloat && - (StringRef(getCPUDefineSuffix(CPU)).startswith("7") || - StringRef(getCPUDefineSuffix(CPU)).startswith("8"))) + .Case("neon", (FPU & NeonFPU) && !SoftFloat) .Default(false); } // FIXME: Should we actually have some table instead of these switches? diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 0154a129af..bce612a2a7 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4735,6 +4735,12 @@ static bool isPermittedNeonBaseType(QualType &Ty, static void HandleNeonVectorTypeAttr(QualType& CurType, const AttributeList &Attr, Sema &S, VectorType::VectorKind VecKind) { + // Target must have NEON + if (!S.Context.getTargetInfo().hasFeature("neon")) { + S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr.getName(); + Attr.setInvalid(); + return; + } // Check the attribute arguments. if (Attr.getNumArgs() != 1) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) diff --git a/test/Analysis/misc-ps-arm.m b/test/Analysis/misc-ps-arm.m index 1ff0f17cea..a9ea3274ae 100644 --- a/test/Analysis/misc-ps-arm.m +++ b/test/Analysis/misc-ps-arm.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple thumbv7-apple-ios0.0.0 -analyze -analyzer-checker=core -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple thumbv7-apple-ios0.0.0 -target-feature +neon -analyze -analyzer-checker=core -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks -Wno-objc-root-class %s // expected-no-diagnostics // - Handle casts of vectors to structs, and loading diff --git a/test/CodeGen/arm-arguments.c b/test/CodeGen/arm-arguments.c index d02a217de4..b6bac9ac44 100644 --- a/test/CodeGen/arm-arguments.c +++ b/test/CodeGen/arm-arguments.c @@ -1,6 +1,6 @@ // REQUIRES: arm-registered-target -// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=APCS-GNU %s -// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi aapcs -emit-llvm -w -o - %s | FileCheck -check-prefix=AAPCS %s +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-feature +neon -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=APCS-GNU %s +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-feature +neon -target-abi aapcs -emit-llvm -w -o - %s | FileCheck -check-prefix=AAPCS %s // APCS-GNU-LABEL: define signext i8 @f0() // AAPCS-LABEL: define arm_aapcscc signext i8 @f0() diff --git a/test/CodeGen/arm-asm-diag.c b/test/CodeGen/arm-asm-diag.c index 925de46c80..944a271e6c 100644 --- a/test/CodeGen/arm-asm-diag.c +++ b/test/CodeGen/arm-asm-diag.c @@ -1,5 +1,5 @@ // REQUIRES: arm-registered-target -// RUN: not %clang_cc1 -triple armv7 %s -S -o /dev/null 2>&1 | FileCheck %s +// RUN: not %clang_cc1 -triple armv7 -target-feature +neon %s -S -o /dev/null 2>&1 | FileCheck %s // rdar://13446483 typedef __attribute__((neon_vector_type(2))) long long int64x2_t; diff --git a/test/CodeGen/arm-asm-warn.c b/test/CodeGen/arm-asm-warn.c index 6112b19d28..a580700661 100644 --- a/test/CodeGen/arm-asm-warn.c +++ b/test/CodeGen/arm-asm-warn.c @@ -1,5 +1,5 @@ // REQUIRES: arm-registered-target -// RUN: %clang_cc1 -triple armv7 %s -emit-llvm -o /dev/null +// RUN: %clang_cc1 -triple armv7 -target-feature +neon %s -emit-llvm -o /dev/null char bar(); diff --git a/test/CodeGen/struct-init.c b/test/CodeGen/struct-init.c index 5273138e4e..30834acec7 100644 --- a/test/CodeGen/struct-init.c +++ b/test/CodeGen/struct-init.c @@ -1,5 +1,5 @@ // REQUIRES: arm-registered-target -// RUN: %clang_cc1 -S -triple armv7-apple-darwin %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -S -triple armv7-apple-darwin -target-feature +neon %s -emit-llvm -o - | FileCheck %s typedef struct _zend_ini_entry zend_ini_entry; struct _zend_ini_entry { diff --git a/test/CodeGen/struct-matching-constraint.c b/test/CodeGen/struct-matching-constraint.c index bdd11c8b90..dfc3014c5d 100644 --- a/test/CodeGen/struct-matching-constraint.c +++ b/test/CodeGen/struct-matching-constraint.c @@ -1,5 +1,5 @@ // REQUIRES: arm-registered-target -// RUN: %clang_cc1 -S -emit-llvm -triple armv7a-apple-darwin %s -o /dev/null +// RUN: %clang_cc1 -S -emit-llvm -triple armv7a-apple-darwin -target-feature +neon %s -o /dev/null typedef unsigned short uint16_t; typedef __attribute__((neon_vector_type(8))) uint16_t uint16x8_t; diff --git a/test/CodeGenCXX/aarch64-mangle-neon-vectors.cpp b/test/CodeGenCXX/aarch64-mangle-neon-vectors.cpp index 86509a0739..2514704f1d 100644 --- a/test/CodeGenCXX/aarch64-mangle-neon-vectors.cpp +++ b/test/CodeGenCXX/aarch64-mangle-neon-vectors.cpp @@ -1,5 +1,5 @@ // REQUIRES: aarch64-registered-target -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon %s -emit-llvm -o - | FileCheck %s typedef unsigned char uint8_t; typedef unsigned short uint16_t; diff --git a/test/CodeGenCXX/mangle-neon-vectors.cpp b/test/CodeGenCXX/mangle-neon-vectors.cpp index 793c89803f..249ec2e99b 100644 --- a/test/CodeGenCXX/mangle-neon-vectors.cpp +++ b/test/CodeGenCXX/mangle-neon-vectors.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple arm-none-linux-gnueabi %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-feature +neon %s -emit-llvm -o - | FileCheck %s typedef float float32_t; typedef __fp16 float16_t; diff --git a/test/Sema/aarch64-neon-vector-types.c b/test/Sema/aarch64-neon-vector-types.c index f4d58ffd09..ddfafbcc58 100644 --- a/test/Sema/aarch64-neon-vector-types.c +++ b/test/Sema/aarch64-neon-vector-types.c @@ -1,5 +1,5 @@ // REQUIRES: aarch64-registered-target -// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -fsyntax-only -verify +// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +neon -fsyntax-only -verify typedef float float32_t; typedef unsigned char poly8_t; diff --git a/test/Sema/neon-vector-types-support.c b/test/Sema/neon-vector-types-support.c new file mode 100644 index 0000000000..6bf8539e47 --- /dev/null +++ b/test/Sema/neon-vector-types-support.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -triple armv7 -fsyntax-only -verify + +typedef __attribute__((neon_vector_type(2))) int int32x2_t; // expected-error{{'neon_vector_type' attribute is not supported for this target}} +typedef __attribute__((neon_polyvector_type(16))) short poly8x16_t; // expected-error{{'neon_polyvector_type' attribute is not supported for this target}} diff --git a/test/Sema/neon-vector-types.c b/test/Sema/neon-vector-types.c index d15a50d28f..d8dd41225a 100644 --- a/test/Sema/neon-vector-types.c +++ b/test/Sema/neon-vector-types.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 %s -triple armv7 -target-feature +neon -fsyntax-only -verify +// RUN: %clang_cc1 %s -triple armv8 -target-feature +neon -fsyntax-only -verify typedef float float32_t; typedef signed char poly8_t; diff --git a/test/SemaCXX/neon-vector-types.cpp b/test/SemaCXX/neon-vector-types.cpp index 336fcd4f18..c2953d713b 100644 --- a/test/SemaCXX/neon-vector-types.cpp +++ b/test/SemaCXX/neon-vector-types.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify "-triple" "thumbv7-apple-ios3.0.0" %s +// RUN: %clang_cc1 -fsyntax-only -verify "-triple" "thumbv7-apple-ios3.0.0" -target-feature +neon %s // rdar://9208404 typedef int MP4Err; -- 2.40.0