@@ -456,6 +456,36 @@ reverse_children::reverse_children(Stmt *S) {
456
456
IE->getNumInits ());
457
457
return ;
458
458
}
459
+ case Stmt::AttributedStmtClass: {
460
+ AttributedStmt *attrStmt = cast<AttributedStmt>(S);
461
+ assert (attrStmt);
462
+
463
+ {
464
+ // for an attributed stmt, the "children()" returns only the NullStmt
465
+ // (;) but semantically the "children" are supposed to be the
466
+ // expressions _within_ i.e. the two square brackets i.e. [[ HERE ]]
467
+ // so we add the subexpressions first, _then_ add the "children"
468
+
469
+ for (const Attr *attr : attrStmt->getAttrs ()) {
470
+
471
+ // i.e. one `assume()`
472
+ CXXAssumeAttr const *assumeAttr = llvm::dyn_cast<CXXAssumeAttr>(attr);
473
+ if (!assumeAttr) {
474
+ continue ;
475
+ }
476
+ // Only handles [[ assume(<assumption>) ]] right now
477
+ Expr *assumption = assumeAttr->getAssumption ();
478
+ childrenBuf.push_back (assumption);
479
+ }
480
+
481
+ // children() for an AttributedStmt is NullStmt(;)
482
+ llvm::append_range (childrenBuf, attrStmt->children ());
483
+
484
+ // This needs to be done *after* childrenBuf has been populated.
485
+ children = childrenBuf;
486
+ }
487
+ return ;
488
+ }
459
489
default :
460
490
break ;
461
491
}
@@ -2475,6 +2505,14 @@ static bool isFallthroughStatement(const AttributedStmt *A) {
2475
2505
return isFallthrough;
2476
2506
}
2477
2507
2508
+ static bool isCXXAssumeAttr (const AttributedStmt *A) {
2509
+ bool hasAssumeAttr = hasSpecificAttr<CXXAssumeAttr>(A->getAttrs ());
2510
+
2511
+ assert ((!hasAssumeAttr || isa<NullStmt>(A->getSubStmt ())) &&
2512
+ " expected [[assume]] not to have children" );
2513
+ return hasAssumeAttr;
2514
+ }
2515
+
2478
2516
CFGBlock *CFGBuilder::VisitAttributedStmt (AttributedStmt *A,
2479
2517
AddStmtChoice asc) {
2480
2518
// AttributedStmts for [[likely]] can have arbitrary statements as children,
@@ -2490,6 +2528,11 @@ CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt *A,
2490
2528
appendStmt (Block, A);
2491
2529
}
2492
2530
2531
+ if (isCXXAssumeAttr (A) && asc.alwaysAdd (*this , A)) {
2532
+ autoCreateBlock ();
2533
+ appendStmt (Block, A);
2534
+ }
2535
+
2493
2536
return VisitChildren (A);
2494
2537
}
2495
2538
0 commit comments