]> granicus.if.org Git - clang/commitdiff
implement PR3962: diagnose more faulty cases of usage of the restrict qualifier....
authorNuno Lopes <nunoplopes@sapo.pt>
Thu, 17 Dec 2009 11:35:26 +0000 (11:35 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Thu, 17 Dec 2009 11:35:26 +0000 (11:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91601 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/declspec.c

index beb44f275a72e29c6d9bc76b2102b0929547b6d3..9123c345c7a877a085976c3489e623484b9ace86 100644 (file)
@@ -1365,6 +1365,8 @@ def warn_typecheck_function_qualifiers : Warning<
   "qualifier on function type %0 has unspecified behavior">;
 def err_typecheck_invalid_restrict_not_pointer : Error<
   "restrict requires a pointer or reference (%0 is invalid)">;
+def err_typecheck_invalid_restrict_not_pointer_noarg : Error<
+  "restrict requires a pointer or reference">;
 def err_typecheck_invalid_restrict_invalid_pointee : Error<
   "pointer to function type %0 may not be 'restrict' qualified">;
 def ext_typecheck_zero_array_size : Extension<
index ee4bd2267686810eb3e3d4f5a7f7cd23c7569c5e..6ed9f7a772b6683881ad4e5b703954989f434f2e 100644 (file)
@@ -1445,7 +1445,6 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
 Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
   // FIXME: Error on auto/register at file scope
   // FIXME: Error on inline/virtual/explicit
-  // FIXME: Error on invalid restrict
   // FIXME: Warn on useless __thread
   // FIXME: Warn on useless const/volatile
   // FIXME: Warn on useless static/extern/typedef/private_extern/mutable
@@ -1467,6 +1466,15 @@ Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
     Tag = dyn_cast<TagDecl>(TagD);
   }
 
+  if (unsigned TypeQuals = DS.getTypeQualifiers()) {
+    // Enforce C99 6.7.3p2: "Types other than pointer types derived from object
+    // or incomplete types shall not be restrict-qualified."
+    if (TypeQuals & DeclSpec::TQ_restrict)
+      Diag(DS.getRestrictSpecLoc(),
+           diag::err_typecheck_invalid_restrict_not_pointer_noarg)
+           << DS.getSourceRange();
+  }
+
   if (DS.isFriendSpecified()) {
     // If we're dealing with a class template decl, assume that the
     // template routines are handling it.
index 5f3ce40516368afecd3405a37f4c258c006e5f40..2cf49aa29da1c5fa0326840f82a8562647d9052e 100644 (file)
@@ -21,3 +21,4 @@ __restrict__ f* v2;  // expected-error {{restrict requires a pointer or referenc
 __restrict__ fptr v3; // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}}
 f *__restrict__ v4;   // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}}
 
+restrict struct hallo; // expected-error {{restrict requires a pointer or reference}}