diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2015-10-16 11:45:02 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-10-16 11:45:02 -0700 |
commit | b775d24d0d9c0f527177bc519164fa75ad2fabe1 (patch) | |
tree | a24f4d6f5e13c221296f5ffe50176db08dc3259e | |
parent | c46e4fef3d41e367eff211b7793812a4f4e57adb (diff) | |
download | gcc-hjl/pr67995/master.tar.gz |
Don't leak ISA to __attribute__ ((target("arch=XXX")))hjl/pr67995/master
When processing __attribute__ ((target("arch=XXX"))), we should clear
the ISA bits in x_ix86_isa_flags first to avoid leaking ISA from
command line.
gcc/
PR target/67995
* config/i386/i386.c (ix86_valid_target_attribute_tree): If
arch= is set, clear all bits in x_ix86_isa_flags, except for
ISA_64BIT, ABI_64, ABI_X32, and CODE16.
gcc/testsuite/
PR target/67995
* gcc.target/i386/pr67995-1.c: New test.
* gcc.target/i386/pr67995-2.c: Likewise.
* gcc.target/i386/pr67995-3.c: Likewise.
-rw-r--r-- | gcc/config/i386/i386.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr67995-1.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr67995-2.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr67995-3.c | 16 |
4 files changed, 60 insertions, 1 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ebe2b0aa8ab..df5a793f5d1 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -6145,7 +6145,18 @@ ix86_valid_target_attribute_tree (tree args, /* If we are using the default tune= or arch=, undo the string assigned, and use the default. */ if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]) - opts->x_ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH]; + { + opts->x_ix86_arch_string + = option_strings[IX86_FUNCTION_SPECIFIC_ARCH]; + + /* If arch= is set, clear all bits in x_ix86_isa_flags, + except for ISA_64BIT, ABI_64, ABI_X32, and CODE16. */ + opts->x_ix86_isa_flags &= (OPTION_MASK_ISA_64BIT + | OPTION_MASK_ABI_64 + | OPTION_MASK_ABI_X32 + | OPTION_MASK_CODE16); + + } else if (!orig_arch_specified) opts->x_ix86_arch_string = NULL; diff --git a/gcc/testsuite/gcc.target/i386/pr67995-1.c b/gcc/testsuite/gcc.target/i386/pr67995-1.c new file mode 100644 index 00000000000..072b1fe787d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr67995-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=haswell" } */ + +unsigned int +__attribute__ ((target("arch=core2"))) +__x86_rdrand(void) +{ + unsigned int retries = 100; + unsigned int val; + + while (__builtin_ia32_rdrand32_step(&val) == 0) /* { dg-error "needs isa option" } */ + if (--retries == 0) + return 0; + + return val; +} diff --git a/gcc/testsuite/gcc.target/i386/pr67995-2.c b/gcc/testsuite/gcc.target/i386/pr67995-2.c new file mode 100644 index 00000000000..632bb63244b --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr67995-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=core2" } */ + +unsigned int +__attribute__ ((target("arch=haswell"))) +__x86_rdrand(void) +{ + unsigned int retries = 100; + unsigned int val; + + while (__builtin_ia32_rdrand32_step(&val) == 0) + if (--retries == 0) + return 0; + + return val; +} diff --git a/gcc/testsuite/gcc.target/i386/pr67995-3.c b/gcc/testsuite/gcc.target/i386/pr67995-3.c new file mode 100644 index 00000000000..11993b74af7 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr67995-3.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=core2" } */ + +unsigned int +__attribute__ ((target("rdrnd"))) +__x86_rdrand(void) +{ + unsigned int retries = 100; + unsigned int val; + + while (__builtin_ia32_rdrand32_step(&val) == 0) + if (--retries == 0) + return 0; + + return val; +} |