From: Alexey Bataev Date: Tue, 20 Dec 2016 16:51:02 +0000 (+0000) Subject: [OPENMP] Fix for PR31416: Clang crashes on OMPCapturedExpr during source X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7206b9e097cd403c3e53ada214b8bbfaca9449b;p=platform%2Fupstream%2Fllvm.git [OPENMP] Fix for PR31416: Clang crashes on OMPCapturedExpr during source based coverage compilation Added source location info to captured expression declaration + fixed source location info for loop based directives. llvm-svn: 290181 --- diff --git a/clang/include/clang/AST/DeclOpenMP.h b/clang/include/clang/AST/DeclOpenMP.h index 1975bc5..30ca79e 100644 --- a/clang/include/clang/AST/DeclOpenMP.h +++ b/clang/include/clang/AST/DeclOpenMP.h @@ -173,18 +173,21 @@ class OMPCapturedExprDecl final : public VarDecl { void anchor() override; OMPCapturedExprDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, - QualType Type) - : VarDecl(OMPCapturedExpr, C, DC, SourceLocation(), SourceLocation(), Id, - Type, nullptr, SC_None) { + QualType Type, SourceLocation StartLoc) + : VarDecl(OMPCapturedExpr, C, DC, StartLoc, SourceLocation(), Id, Type, + nullptr, SC_None) { setImplicit(); } public: static OMPCapturedExprDecl *Create(ASTContext &C, DeclContext *DC, - IdentifierInfo *Id, QualType T); + IdentifierInfo *Id, QualType T, + SourceLocation StartLoc); static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, unsigned ID); + SourceRange getSourceRange() const override LLVM_READONLY; + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == OMPCapturedExpr; } diff --git a/clang/lib/AST/DeclOpenMP.cpp b/clang/lib/AST/DeclOpenMP.cpp index 5b06ce0..95e44ac 100644 --- a/clang/lib/AST/DeclOpenMP.cpp +++ b/clang/lib/AST/DeclOpenMP.cpp @@ -90,13 +90,18 @@ OMPDeclareReductionDecl::getPrevDeclInScope() const { void OMPCapturedExprDecl::anchor() {} OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC, - IdentifierInfo *Id, - QualType T) { - return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T); + IdentifierInfo *Id, QualType T, + SourceLocation StartLoc) { + return new (C, DC) OMPCapturedExprDecl(C, DC, Id, T, StartLoc); } OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType()); + return new (C, ID) + OMPCapturedExprDecl(C, nullptr, nullptr, QualType(), SourceLocation()); } +SourceRange OMPCapturedExprDecl::getSourceRange() const { + assert(hasInit()); + return SourceRange(getInit()->getLocStart(), getInit()->getLocEnd()); +} diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index f7e0210..ba7bb6b5 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1753,7 +1753,8 @@ static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, } WithInit = true; } - auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); + auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, + CaptureExpr->getLocStart()); if (!WithInit) CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); S.CurContext->addHiddenDecl(CED); @@ -3862,14 +3863,16 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, Scope *CurScope = DSA.getCurScope(); for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { if (PreCond.isUsable()) { - PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, - PreCond.get(), IterSpaces[Cnt].PreCond); + PreCond = + SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, + PreCond.get(), IterSpaces[Cnt].PreCond); } auto N = IterSpaces[Cnt].NumIterations; + SourceLocation Loc = N->getExprLoc(); AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; if (LastIteration32.isUsable()) LastIteration32 = SemaRef.BuildBinOp( - CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), + CurScope, Loc, BO_Mul, LastIteration32.get(), SemaRef .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), Sema::AA_Converting, @@ -3877,7 +3880,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, .get()); if (LastIteration64.isUsable()) LastIteration64 = SemaRef.BuildBinOp( - CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), + CurScope, Loc, BO_Mul, LastIteration64.get(), SemaRef .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), Sema::AA_Converting, @@ -3912,7 +3915,8 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, ExprResult NumIterations = LastIteration; { LastIteration = SemaRef.BuildBinOp( - CurScope, SourceLocation(), BO_Sub, LastIteration.get(), + CurScope, LastIteration.get()->getExprLoc(), BO_Sub, + LastIteration.get(), SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); if (!LastIteration.isUsable()) return 0; @@ -3931,7 +3935,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, // Prepare SaveRef + 1. NumIterations = SemaRef.BuildBinOp( - CurScope, SourceLocation(), BO_Add, SaveRef.get(), + CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); if (!NumIterations.isUsable()) return 0; diff --git a/clang/test/OpenMP/for_codegen.cpp b/clang/test/OpenMP/for_codegen.cpp index 4706255..b27bd7b 100644 --- a/clang/test/OpenMP/for_codegen.cpp +++ b/clang/test/OpenMP/for_codegen.cpp @@ -2,10 +2,13 @@ // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG +// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm -fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | FileCheck %s --check-prefix=PROF-INSTR-PATH // // expected-no-diagnostics #ifndef HEADER #define HEADER +// PROF-INSTR-PATH: constant [25 x i8] c"for_codegen-test.profraw\00" + // CHECK: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* } // CHECK-DAG: [[IMPLICIT_BARRIER_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 66, i32 0, i32 0, i8* // CHECK-DAG: [[I:@.+]] = global i8 1,