[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 17 02:50:23 PDT 2024


================
@@ -3903,7 +3904,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
   if (R.isInvalid())
     return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html says
+  // "The values of 0 and 1 block any unrolling of the loop."
+  // The values doesn't have to be strictly positive in '#pragma GCC unroll' and
+  // '#pragma unroll' cases.
+  bool ValueIsPositive = PragmaNameInfo->isStr("unroll")
----------------
yronglin wrote:

Thanks for your review! I've add a bool parameter `AllowZero` here. I want to go further, should we move all the string checks in `Sema::handleLoopHintAttr` to `Parser::HandlePragmaLoopHint`? (https://github.com/llvm/llvm-project/blob/ac791888bbbe58651e597cf7a4b2276424b77a92/clang/lib/Sema/SemaStmtAttr.cpp#L108) , these checks used to classify `LoopHintAttr::OptionType` and `LoopHintAttr::LoopHintState`, I'd like to classification in `Parser::HandlePragmaLoopHint` and pass the result into `Sema::handleLoopHintAttr` through `ParsedAttr`.

https://github.com/llvm/llvm-project/pull/88666


More information about the cfe-commits mailing list