Skip to content

[clang] Fix assertion failure when printing atomic apvalues #85259

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 1 commit into from
Mar 26, 2024

Conversation

tbaederr
Copy link
Contributor

When printing an _Atomic(some struct type), we would later run into an assertion because we do a Ty->castAs<RecordType>(), which doesn't work with an AtomicType.

Not sure how to best write a test for, this, but OTOH, printPretty is currently only used for debugging as far as I know(?).

@tbaederr tbaederr added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Mar 14, 2024
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

When printing an _Atomic(some struct type), we would later run into an assertion because we do a Ty-&gt;castAs&lt;RecordType&gt;(), which doesn't work with an AtomicType.

Not sure how to best write a test for, this, but OTOH, printPretty is currently only used for debugging as far as I know(?).


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

1 Files Affected:

  • (modified) clang/lib/AST/APValue.cpp (+3)
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 4eae308ef5b34c..d8042321319a67 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -704,6 +704,9 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
     return;
   }
 
+  if (const auto *AT = Ty->getAs<AtomicType>())
+    Ty = AT->getValueType();
+
   switch (getKind()) {
   case APValue::None:
     Out << "<out of lifetime>";

@tbaederr
Copy link
Contributor Author

Ping

@tbaederr tbaederr requested review from AaronBallman and shafik March 18, 2024 15:02
@tbaederr
Copy link
Contributor Author

Ping

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 but this should be testable because getAsString() uses printPretty():

return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
,
return Printable.getAsString(Ctx, T);
, etc

@tbaederr
Copy link
Contributor Author

Right, I was just hoping for an existing unittest for APValue.

@tbaederr tbaederr merged commit 6a6f9bf into llvm:main Mar 26, 2024
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