Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Added check for unexpanded pack in attribute [[assume]] #91841

Closed
wants to merge 0 commits into from

Conversation

azmat-y
Copy link
Contributor

@azmat-y azmat-y commented May 11, 2024

Added check for unexpanded parameter pack in attribute [[assume]]. This solves #91232.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 11, 2024
@llvmbot
Copy link
Member

llvmbot commented May 11, 2024

@llvm/pr-subscribers-clang

Author: Azmat Yusuf (azmat-y)

Changes

Added check for unexpanded parameter pack in attribute [[assume]]. This solves #91232.


Full diff: https://github.com/llvm/llvm-project/pull/91841.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaStmtAttr.cpp (+5)
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A,
   }
 
   auto *Assumption = A.getArgAsExpr(0);
+
+  if (DiagnoseUnexpandedParameterPack(Assumption)) {
+    return ExprError();
+  }
+
   if (Assumption->getDependence() == ExprDependence::None) {
     ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
     if (Res.isInvalid())

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs tests to make sure this is actually doing what it’s supposed to do.

@azmat-y
Copy link
Contributor Author

azmat-y commented May 11, 2024

Would I be correct in assuming that the test would be somewhat similar to this.

llvm-project/clang/test/Sema/unroll-template-value-crash.cpp

// RUN: %clang_cc1 -x c++ -verify %s
// expected-no-diagnostics

template <int Unroll> void foo() {
  #pragma unroll Unroll
  for (int i = 0; i < Unroll; ++i);

  #pragma GCC unroll Unroll
  for (int i = 0; i < Unroll; ++i);
}

Can you point me towards information on clang_cc1 and similar arguments used for lit. I have scanned through lit but could not find a mention for it.

@Sirraide
Copy link
Member

I’d recommend just adding the tests to wherever the [[assume]] attribute is already being tested; that’d be somewhere in test/SemaCXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants