@@ -456,6 +456,45 @@ 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 (auto *child : attrStmt->children ()) {
470
+ llvm::errs () << " \n children=" ;
471
+ child->dump ();
472
+ }
473
+
474
+ for (const Attr *attr : attrStmt->getAttrs ()) {
475
+ {
476
+ llvm::errs () << " \n attr=" ;
477
+ attr->printPretty (llvm::errs (), PrintingPolicy{LangOptions{}});
478
+ }
479
+
480
+ // i.e. one `assume()`
481
+ CXXAssumeAttr const *assumeAttr = llvm::dyn_cast<CXXAssumeAttr>(attr);
482
+ if (!assumeAttr) {
483
+ continue ;
484
+ }
485
+ // Only handles [[ assume(<assumption>) ]] right now
486
+ Expr *assumption = assumeAttr->getAssumption ();
487
+ childrenBuf.push_back (assumption);
488
+ }
489
+
490
+ // children() for an AttributedStmt is NullStmt(;)
491
+ llvm::append_range (childrenBuf, attrStmt->children ());
492
+
493
+ // This needs to be done *after* childrenBuf has been populated.
494
+ children = childrenBuf;
495
+ }
496
+ return ;
497
+ }
459
498
default :
460
499
break ;
461
500
}
@@ -2475,6 +2514,14 @@ static bool isFallthroughStatement(const AttributedStmt *A) {
2475
2514
return isFallthrough;
2476
2515
}
2477
2516
2517
+ static bool isCXXAssumeAttr (const AttributedStmt *A) {
2518
+ bool hasAssumeAttr = hasSpecificAttr<CXXAssumeAttr>(A->getAttrs ());
2519
+
2520
+ assert ((!hasAssumeAttr || isa<NullStmt>(A->getSubStmt ())) &&
2521
+ " expected [[assume]] not to have children" );
2522
+ return hasAssumeAttr;
2523
+ }
2524
+
2478
2525
CFGBlock *CFGBuilder::VisitAttributedStmt (AttributedStmt *A,
2479
2526
AddStmtChoice asc) {
2480
2527
// AttributedStmts for [[likely]] can have arbitrary statements as children,
@@ -2490,6 +2537,11 @@ CFGBlock *CFGBuilder::VisitAttributedStmt(AttributedStmt *A,
2490
2537
appendStmt (Block, A);
2491
2538
}
2492
2539
2540
+ if (isCXXAssumeAttr (A) && asc.alwaysAdd (*this , A)) {
2541
+ autoCreateBlock ();
2542
+ appendStmt (Block, A);
2543
+ }
2544
+
2493
2545
return VisitChildren (A);
2494
2546
}
2495
2547
0 commit comments