[PATCH] D53705: [OpenCL] Postpone PSV address space diagnostic

Sven van Haastregt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 25 08:26:37 PDT 2018


svenvh created this revision.
svenvh added reviewers: Anastasia, rjmccall.
Herald added subscribers: cfe-commits, yaxunl.

In OpenCL C++ mode, the "program scope variable must reside ..."
diagnostic is firing early in some cases, potentially confusing the
user.  It is the first diagnostic reported for

  int g(global int *p) {}

but the actual problem is the undeclared identifier `global`.

The main reason to improve error reporting for the example above is
that OpenCL C address space qualifiers such as `global` are not part
of OpenCL C++.  This means the PSV diagnostic will fire when porting
OpenCL C code to OpenCL C++ if an address space qualifier is left in
by accident.

The PSV diagnostic is emitted for the example above because the parser
believes `g` is a variable declaration instead of a function
declaration.  This seems to be inherent to C++ parsing, so postpone
the PSV diagnostic until we have parsed the entire declarator group.
We still get the PSV diagnostic for the example, but it is no longer
the first so it should be easier for the user to see what the actual
problem is.


Repository:
  rC Clang

https://reviews.llvm.org/D53705

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/invalid-qualifier.cl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53705.171108.patch
Type: text/x-patch
Size: 8194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181025/a9363c19/attachment.bin>


More information about the cfe-commits mailing list