Skip to content

Fix to attribute plugins reaching an unreachable #70877

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

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

amykhuang
Copy link
Collaborator

@amykhuang amykhuang commented Nov 1, 2023

0faee97 broke attribute plugins. Specifically, it added a call to getAttributeSpellingListIndex() in situations that reached an unreachable statement. This patch adds a check before calling that to avoid hitting the unreachable.

clang/test/Frontend/plugin-attribute.cpp has been broken since 0faee97, and this patch fixes it.

Bug: 70702

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

llvmbot commented Nov 1, 2023

@llvm/pr-subscribers-clang

Author: Amy Huang (amykhuang)

Changes

0faee97 made the attribute plugin code hit an unreachable.

Bug: 70702


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

1 Files Affected:

  • (modified) clang/lib/Sema/ParsedAttr.cpp (+6-2)
diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..2d6d17e74f6e38d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,9 +193,13 @@ bool ParsedAttr::isTypeAttr() const { return getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
+  Kind K = getParsedKind();
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+                     K != NoSemaHandlerAttribute;
   return getInfo().existsInTarget(Target) &&
-         getInfo().spellingExistsInTarget(Target,
-                                          getAttributeSpellingListIndex());
+         (HasSpelling &&
+          getInfo().spellingExistsInTarget(Target,
+                                          getAttributeSpellingListIndex()));
 }
 
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }

Copy link

github-actions bot commented Nov 1, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@shafik
Copy link
Collaborator

shafik commented Nov 3, 2023

Can you please add a more detailed description of the problem and what the fix actually is. The description is what ends up in the git log and it is important that we have enough details there to understand the PR and what changes it makes.

I do not see a test, can this fix be tested?

@AaronBallman
Copy link
Collaborator

Can you please add a more detailed description of the problem and what the fix actually is. The description is what ends up in the git log and it is important that we have enough details there to understand the PR and what changes it makes.

I do not see a test, can this fix be tested?

We could add a test with a // REQUIRES: plugins, examples line on the RUN line. We don't have very many tests for plugins in Clang currently, but adding one here would help catch regressions.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

As far as the changes go, they look correct to me. Thank you for the fix! Can you try adding test coverage for the change?

@amykhuang
Copy link
Collaborator Author

Huh, apparently my no-unique-address patch did break existing plugin tests (e.g. clang/test/Frontend/plugin-attribute.cpp), and this patch doesn't fix it

@amykhuang
Copy link
Collaborator Author

Updated the PR description and the patch. The existing clang/test/Frontend/plugin-attribute.cpp seems sufficient for test coverage. (I guess it wasn't being tested on bots though, otherwise we would have seen it?)

@amykhuang
Copy link
Collaborator Author

ping for review?

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

ping for review?

My apologies for the delay!

The changes LGTM but there is a precommit CI failure with libc++. As best I can tell, that looks to be a transient issue and not caused by your patch, but it would be good to verify that before landing. (I would be really surprised if this change managed to break the demangler behavior.) CC @ldionne @mordante @philnik777 for other opinions.

@ldionne
Copy link
Member

ldionne commented Nov 16, 2023

This is weird, it's the first time I see this and I couldn't find any obvious offending commit. It looks like it shouldn't be related, but at the same time we're not seeing this issue in any of the other builds in the Clang pipeline. You could consider updating the PR with the latest main content to re-trigger a CI run and see if that still fails.

@AaronBallman
Copy link
Collaborator

Oh wow, same failure a second time...

Ohh, this looks familiar now, but... it was already fixed, so why are we still hitting this failure?

| expected: clang::TreeTransform<(anonymous namespace)::CurrentInstantiationRebuilder>::RebuildArrayType(clang::QualType, clang::ArraySizeModifier, llvm::APInt const*, clang::Expr*, unsigned int, clang::SourceRange)
| got: 0,   clang::TreeTransform<(anonymous namespace)::CurrentInstantiationRebuilder>::RebuildArrayType(clang::QualType, clang::ArrayType::ArraySizeModifier, llvm::APInt const*, clang::Expr*, unsigned int, clang::SourceRange)

should have been fixed by f5f4c5b over two weeks ago. CC @Endilll

@Endilll
Copy link
Contributor

Endilll commented Nov 16, 2023

This was fixed by e11148f
I checked the logs, and exactly the part that this commit fixed is failing.

@Endilll
Copy link
Contributor

Endilll commented Nov 16, 2023

https://github.com/amykhuang/llvm-project/tree/attr-plugin
This branch is 2 commits ahead, 1684 commits behind llvm:main.

Yeah, this branch is missing all November commits, including aforementioned fix.

@amykhuang
Copy link
Collaborator Author

Whoops, sorry about that, I guess I am failing to update my fork properly...

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM assuming precommit CI is now fixed.

@amykhuang amykhuang merged commit 0ba5f6e into llvm:main Nov 20, 2023
@amykhuang amykhuang deleted the attr-plugin branch April 2, 2025 17:36
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.

6 participants