-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][Sema] Print more static_assert exprs #74852
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
base: main
Are you sure you want to change the base?
Changes from all commits
f281d34
2fd5fc4
db9118f
153d363
6597d6c
c270701
e769f15
345b787
86b0623
8db11a3
2d3af43
ee5aeca
4953e13
4ed5047
f139207
9ccd9ef
d5f626f
38f1724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "clang/AST/Expr.h" | ||
#include "clang/AST/ExprCXX.h" | ||
#include "clang/AST/Type.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
using namespace clang; | ||
|
@@ -711,11 +712,54 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy, | |
case APValue::Indeterminate: | ||
Out << "<uninitialized>"; | ||
return; | ||
case APValue::Int: | ||
case APValue::Int: { | ||
const APSInt &Val = getInt(); | ||
if (const EnumType *ET = Ty->getAs<EnumType>()) { | ||
// print the enumerator name if requested (and one exists) | ||
if (Policy.UseEnumerators) { | ||
for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) { | ||
if (APSInt::isSameValue(ECD->getInitVal(), Val)) { | ||
if (ECD->isCXXClassMember()) | ||
ECD->printQualifiedName(Out, Policy); | ||
else | ||
ECD->printName(Out, Policy); | ||
Comment on lines
+722
to
+725
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a weird heuristic: without it, we were trying to print a function-local enum constant as It might be better to go back to just always using the QualifiedName though, I'm not sure. |
||
return; | ||
} | ||
} | ||
} | ||
|
||
// otherwise, we print it as a cast from `Val` | ||
if (ET->hasUnnamedOrLocalType()) { | ||
// e.g. `(unnamed enum at ...)7`, unless... | ||
if (const EnumDecl *Defn = ET->getDecl()->getDefinition()) { | ||
// ... can identify the defn somehow | ||
if (const IdentifierInfo *II = Defn->getIdentifier()) | ||
Out << '(' << II->getName() << ')'; | ||
else if (const TypedefNameDecl *Typedef = | ||
Defn->getTypedefNameForAnonDecl()) { | ||
assert(Typedef->getIdentifier() && "Typedef without identifier?"); | ||
Out << '(' << Typedef->getIdentifier()->getName() << ')'; | ||
} else if (const NamedDecl *ND = dyn_cast_if_present<NamedDecl>( | ||
Defn->getNextDeclInContext())) { | ||
// if it's part of a declaration, then use `(decltype(...))7` | ||
Out << "(decltype("; | ||
ND->printQualifiedName(Out); | ||
Out << "))"; | ||
Comment on lines
+742
to
+747
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it really make sense to support the unnamed case? |
||
} else | ||
Defn->printQualifiedName(Out); | ||
} else | ||
ET->getDecl()->printQualifiedName(Out); | ||
} else { | ||
// e.g. `(E)7` for some `enum E {};` | ||
Out << '(' << Ty << ')'; | ||
} | ||
} | ||
|
||
if (Ty->isBooleanType()) | ||
Out << (getInt().getBoolValue() ? "true" : "false"); | ||
Out << (Val.getBoolValue() ? "true" : "false"); | ||
else | ||
Out << getInt(); | ||
Out << Val; | ||
} | ||
return; | ||
case APValue::Float: | ||
Out << GetApproxValue(getFloat()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
320?