diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp')
| -rw-r--r-- | contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp | 61 | 
1 files changed, 59 insertions, 2 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp b/contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp index 6adf99531e30..9ec185153d12 100644 --- a/contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp +++ b/contrib/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp @@ -4564,6 +4564,12 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {      if (LHSCondVal) { // If we have 1 && X, just emit X.        CGF.incrementProfileCounter(E); +      // If the top of the logical operator nest, reset the MCDC temp to 0. +      if (CGF.MCDCLogOpStack.empty()) +        CGF.maybeResetMCDCCondBitmap(E); + +      CGF.MCDCLogOpStack.push_back(E); +        Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS());        // If we're generating for profiling or coverage, generate a branch to a @@ -4572,6 +4578,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {        // "FalseBlock" after the increment is done.        if (InstrumentRegions &&            CodeGenFunction::isInstrumentedCondition(E->getRHS())) { +        CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);          llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end");          llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt");          Builder.CreateCondBr(RHSCond, RHSBlockCnt, FBlock); @@ -4581,6 +4588,11 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {          CGF.EmitBlock(FBlock);        } +      CGF.MCDCLogOpStack.pop_back(); +      // If the top of the logical operator nest, update the MCDC bitmap. +      if (CGF.MCDCLogOpStack.empty()) +        CGF.maybeUpdateMCDCTestVectorBitmap(E); +        // ZExt result to int or bool.        return Builder.CreateZExtOrBitCast(RHSCond, ResTy, "land.ext");      } @@ -4590,6 +4602,12 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {        return llvm::Constant::getNullValue(ResTy);    } +  // If the top of the logical operator nest, reset the MCDC temp to 0. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeResetMCDCCondBitmap(E); + +  CGF.MCDCLogOpStack.push_back(E); +    llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end");    llvm::BasicBlock *RHSBlock  = CGF.createBasicBlock("land.rhs"); @@ -4622,6 +4640,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {    // condition coverage.    if (InstrumentRegions &&        CodeGenFunction::isInstrumentedCondition(E->getRHS())) { +    CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);      llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt");      Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock);      CGF.EmitBlock(RHSBlockCnt); @@ -4639,6 +4658,11 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {    // Insert an entry into the phi node for the edge with the value of RHSCond.    PN->addIncoming(RHSCond, RHSBlock); +  CGF.MCDCLogOpStack.pop_back(); +  // If the top of the logical operator nest, update the MCDC bitmap. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeUpdateMCDCTestVectorBitmap(E); +    // Artificial location to preserve the scope information    {      auto NL = ApplyDebugLocation::CreateArtificial(CGF); @@ -4680,6 +4704,12 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {      if (!LHSCondVal) { // If we have 0 || X, just emit X.        CGF.incrementProfileCounter(E); +      // If the top of the logical operator nest, reset the MCDC temp to 0. +      if (CGF.MCDCLogOpStack.empty()) +        CGF.maybeResetMCDCCondBitmap(E); + +      CGF.MCDCLogOpStack.push_back(E); +        Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS());        // If we're generating for profiling or coverage, generate a branch to a @@ -4688,6 +4718,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {        // "FalseBlock" after the increment is done.        if (InstrumentRegions &&            CodeGenFunction::isInstrumentedCondition(E->getRHS())) { +        CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);          llvm::BasicBlock *FBlock = CGF.createBasicBlock("lor.end");          llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("lor.rhscnt");          Builder.CreateCondBr(RHSCond, FBlock, RHSBlockCnt); @@ -4697,6 +4728,11 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {          CGF.EmitBlock(FBlock);        } +      CGF.MCDCLogOpStack.pop_back(); +      // If the top of the logical operator nest, update the MCDC bitmap. +      if (CGF.MCDCLogOpStack.empty()) +        CGF.maybeUpdateMCDCTestVectorBitmap(E); +        // ZExt result to int or bool.        return Builder.CreateZExtOrBitCast(RHSCond, ResTy, "lor.ext");      } @@ -4706,6 +4742,12 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {        return llvm::ConstantInt::get(ResTy, 1);    } +  // If the top of the logical operator nest, reset the MCDC temp to 0. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeResetMCDCCondBitmap(E); + +  CGF.MCDCLogOpStack.push_back(E); +    llvm::BasicBlock *ContBlock = CGF.createBasicBlock("lor.end");    llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("lor.rhs"); @@ -4742,6 +4784,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {    // condition coverage.    if (InstrumentRegions &&        CodeGenFunction::isInstrumentedCondition(E->getRHS())) { +    CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);      llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("lor.rhscnt");      Builder.CreateCondBr(RHSCond, ContBlock, RHSBlockCnt);      CGF.EmitBlock(RHSBlockCnt); @@ -4755,6 +4798,11 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {    CGF.EmitBlock(ContBlock);    PN->addIncoming(RHSCond, RHSBlock); +  CGF.MCDCLogOpStack.pop_back(); +  // If the top of the logical operator nest, update the MCDC bitmap. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeUpdateMCDCTestVectorBitmap(E); +    // ZExt result to int.    return Builder.CreateZExtOrBitCast(PN, ResTy, "lor.ext");  } @@ -4899,6 +4947,10 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {      return Builder.CreateSelect(CondV, LHS, RHS, "cond");    } +  // If the top of the logical operator nest, reset the MCDC temp to 0. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeResetMCDCCondBitmap(condExpr); +    llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");    llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");    llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end"); @@ -4934,6 +4986,11 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {    llvm::PHINode *PN = Builder.CreatePHI(LHS->getType(), 2, "cond");    PN->addIncoming(LHS, LHSBlock);    PN->addIncoming(RHS, RHSBlock); + +  // If the top of the logical operator nest, update the MCDC bitmap. +  if (CGF.MCDCLogOpStack.empty()) +    CGF.maybeUpdateMCDCTestVectorBitmap(condExpr); +    return PN;  } @@ -5292,8 +5349,8 @@ static GEPOffsetAndOverflow EmitGEPOffsetInBytes(Value *BasePtr, Value *GEPVal,      } else {        // Otherwise this is array-like indexing. The local offset is the index        // multiplied by the element size. -      auto *ElementSize = llvm::ConstantInt::get( -          IntPtrTy, DL.getTypeAllocSize(GTI.getIndexedType())); +      auto *ElementSize = +          llvm::ConstantInt::get(IntPtrTy, GTI.getSequentialElementStride(DL));        auto *IndexS = Builder.CreateIntCast(Index, IntPtrTy, /*isSigned=*/true);        LocalOffset = eval(BO_Mul, ElementSize, IndexS);      }  | 
