Bug 45697 - __restrict__ inconsistent in presence of typedefs
Summary: __restrict__ inconsistent in presence of typedefs
Status: SUSPENDED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: restrict
  Show dependency treegraph
 
Reported: 2010-09-16 23:52 UTC by Evan Martin
Modified: 2024-04-05 23:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-09-17 09:39:43


Attachments
patch (825 bytes, patch)
2011-07-08 14:57 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Martin 2010-09-16 23:52:37 UTC
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

typedef unsigned char uint8_t;
void f(uint8_t __restrict__ foo[]) {
  // no warnings/errors
}
void f2(unsigned char __restrict__ foo[]) {
  // doesn't compile::
  // test.cc:6: error: ‘__restrict__’ qualifiers cannot be applied to ‘unsigned char’
}

The two functions should be equivalent, I think -- both erroring or neither erroring.  Verbose details follow.


$ gcc -v -save-temps test.cc
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=i486'
 /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -E -quiet -v -D_GNU_SOURCE test.cc -D_FORTIFY_SOURCE=2 -mtune=generic -march=i486 -fpch-preprocess -fstack-protector -o test.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.4
 /usr/include/c++/4.4/i486-linux-gnu
 /usr/include/c++/4.4/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=i486'
 /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cc -mtune=generic -march=i486 -auxbase test -version -fstack-protector -o test.s
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
	compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
	compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 35224f2c24023afb0a5be7befe8d5f3f
test.cc:6: error: ‘__restrict__’ qualifiers cannot be applied to ‘unsigned char’
Comment 1 Richard Biener 2010-09-17 09:39:43 UTC
Confirmed.  Both variants are rejected when using the C frontend.
Comment 2 Jason Merrill 2011-07-08 14:53:33 UTC
C++ ignores inappropriate cv-qualifications introduced through the use of a typedef or template type parameter:

int i;
typedef int& IR;
IR const ir1 = i; // OK
int& const ir2 = i; // error

G++ is treating restrict the same way.  It's not clear to me that this is the right thing to do, but it's not clear that it's wrong, either.
Comment 3 Jason Merrill 2011-07-08 14:57:52 UTC
Created attachment 24715 [details]
patch

But here's a patch against pre-4.7 to do what you want.
Comment 4 Evan Martin 2011-07-11 22:38:49 UTC
Sorry, I should have linked to the bug that prompted this bug report.
http://code.google.com/p/skia/issues/detail?id=63

Briefly, the Skia library (used by Google Chrome and Android) has usage of restrict that Clang complains about.  In trying to reduce the problem to a test case, I encountered the below inconsistency in gcc and thought I'd be a good citizen to file a bug.  If the Skia code is just wrong by the spec, it's probably not worth changing gcc.

The Skia usage of restrict presumably worked on some platform, or they wouldn't have checked it in.  But perhaps it was ignored on those platforms anyway.  I have asked on the Skia bug for more information.  It seems likely to me this bug should be WONTFIXed.
Comment 5 Jason Merrill 2011-07-12 12:47:30 UTC
Since clang handles this differently, I think I'll leave it as SUSPENDED for now.