From e23d82b457517d0302ebabefad32118ac7b78023 Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Thu, 11 Jun 2015 17:00:04 -0700 Subject: Move the error for pointers in structures earlier in the compile. Bug: 21597073 This fixes an issue where a function argument is not checked for compatibility until the reflected code generation (at which point the message is far more cryptic). We do this by checking parameters for externally-visible functions and externally-visible globals in our ValidateType() routine. Change-Id: I5ab9db1a11ed0e395c7623f1c9997632da057269 (cherry picked from commit ab94bccca64c9b126cbd1b732aa5e681d8639b99) --- slang_rs_check_ast.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'slang_rs_check_ast.cpp') diff --git a/slang_rs_check_ast.cpp b/slang_rs_check_ast.cpp index a7c1025..7c96291 100644 --- a/slang_rs_check_ast.cpp +++ b/slang_rs_check_ast.cpp @@ -148,27 +148,24 @@ void RSCheckAST::ValidateFunctionDecl(clang::FunctionDecl *FD) { return; } - if (mIsFilterscript) { - // Validate parameters for Filterscript. - size_t numParams = FD->getNumParams(); + clang::QualType resultType = FD->getReturnType().getCanonicalType(); + bool isExtern = (FD->getFormalLinkage() == clang::ExternalLinkage); - clang::QualType resultType = FD->getReturnType().getCanonicalType(); + // We use FD as our NamedDecl in the case of a bad return type. + if (!RSExportType::ValidateType(Context, C, resultType, FD, + FD->getLocStart(), mTargetAPI, + mIsFilterscript, isExtern)) { + mValid = false; + } - // We use FD as our NamedDecl in the case of a bad return type. - if (!RSExportType::ValidateType(Context, C, resultType, FD, - FD->getLocStart(), mTargetAPI, - mIsFilterscript)) { + size_t numParams = FD->getNumParams(); + for (size_t i = 0; i < numParams; i++) { + clang::ParmVarDecl *PVD = FD->getParamDecl(i); + clang::QualType QT = PVD->getType().getCanonicalType(); + if (!RSExportType::ValidateType(Context, C, QT, PVD, PVD->getLocStart(), + mTargetAPI, mIsFilterscript, isExtern)) { mValid = false; } - - for (size_t i = 0; i < numParams; i++) { - clang::ParmVarDecl *PVD = FD->getParamDecl(i); - clang::QualType QT = PVD->getType().getCanonicalType(); - if (!RSExportType::ValidateType(Context, C, QT, PVD, PVD->getLocStart(), - mTargetAPI, mIsFilterscript)) { - mValid = false; - } - } } bool saveKernel = mInKernel; @@ -258,10 +255,14 @@ void RSCheckAST::VisitExpr(clang::Expr *E) { // First we skip implicit casts (things like function calls and explicit // array accesses rely heavily on them and they are valid. E = E->IgnoreImpCasts(); + + // Expressions at this point in the checker are not externally visible. + static const bool kIsExtern = false; + if (mIsFilterscript && !Slang::IsLocInRSHeaderFile(E->getExprLoc(), mSM) && !RSExportType::ValidateType(Context, C, E->getType(), nullptr, E->getExprLoc(), - mTargetAPI, mIsFilterscript)) { + mTargetAPI, mIsFilterscript, kIsExtern)) { mValid = false; } else { // Only visit sub-expressions if we haven't already seen a violation. -- cgit v1.2.3