diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-01-05 14:39:27 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-01-05 14:39:27 +0000 |
commit | cf04d04ccf6879aa943e09ca8066105e692ab2df (patch) | |
tree | 9cbbe5d106ea95522f5d11b5ae5d60996979aeac /clang/lib/Parse/ParseExpr.cpp | |
parent | e09fcfb1085dc7c64b6ba4ba078757e1d93b4089 (diff) | |
download | bcm5719-llvm-cf04d04ccf6879aa943e09ca8066105e692ab2df.tar.gz bcm5719-llvm-cf04d04ccf6879aa943e09ca8066105e692ab2df.zip |
[OpenCL] Disallow taking an address of a function.
An undecorated function designator implies taking the address of a function,
which is illegal in OpenCL. Implementing a check for this earlier to allow
the error to be reported even in the presence of other more obvious errors.
Patch by Neil Hickey!
http://reviews.llvm.org/D15691
llvm-svn: 256838
Diffstat (limited to 'clang/lib/Parse/ParseExpr.cpp')
-rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 490bd5ada62..1fd98c140e0 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1334,8 +1334,23 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, return ExprError(); } + // Check to see whether Res is a function designator only. If it is and we + // are compiling for OpenCL, we need to return an error as this implies + // that the address of the function is being taken, which is illegal in CL. + // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res); + Res = ParsePostfixExpressionSuffix(Res); + if (getLangOpts().OpenCL) + if (Expr *PostfixExpr = Res.get()) { + QualType Ty = PostfixExpr->getType(); + if (!Ty.isNull() && Ty->isFunctionType()) { + Diag(PostfixExpr->getExprLoc(), + diag::err_opencl_taking_function_address_parser); + return ExprError(); + } + } + + return Res; } /// \brief Once the leading part of a postfix-expression is parsed, this |