-
Notifications
You must be signed in to change notification settings - Fork 246
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
Check for C11 atomics in and around VisitQualType #302
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -189,6 +189,24 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> { | |
astEncoder(ast) {} | ||
|
||
void VisitQualType(const QualType &QT) { | ||
if(isa<AtomicType>(QT)) { | ||
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 check needs to be moved inside the |
||
// No printC11AtomicError available here and no location | ||
// information either -- should better have been caught at the | ||
// caller, but catching it here is still better than the | ||
// nondescript error messages that would come later. | ||
std::string msg = "C11 Atomics are not supported. No precise " | ||
"location information available. Aborting."; | ||
|
||
auto &DiagEngine = Context->getDiagnostics(); | ||
// Prefix warnings with `c2rust`, so the user can distinguish | ||
// our warning messages from those generated by clang itself. | ||
const auto ID = DiagEngine.getCustomDiagID(DiagnosticsEngine::Error, | ||
"c2rust: %0"); | ||
DiagEngine.Report(SourceLocation::getFromRawEncoding(0), ID).AddString(msg); | ||
|
||
abort(); | ||
} | ||
|
||
if (!QT.isNull()) { | ||
auto s = QT.split(); | ||
|
||
|
@@ -2188,6 +2206,17 @@ class TranslateASTVisitor final | |
cbor_encode_boolean(array, D->isImplicit()); | ||
}); | ||
|
||
if(isa<AtomicType>(typeForDecl)) { | ||
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. see previous comment. |
||
// This case is especially checked as that's what happens when | ||
// clang's stdatomic.h is traversed. Other callers of VisitQualType | ||
// could get the same check to preserve the location information | ||
// available in Decl but not in Type, but those are more likely not | ||
// to be hit, and can fall back to the less descriptive error from | ||
// inside there. | ||
printC11AtomicError(D); | ||
abort(); | ||
} | ||
|
||
typeEncoder.VisitQualType(typeForDecl); | ||
|
||
return true; | ||
|
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.
nit: looks like this could be
QT.isAtomicType()
.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.
Nope -- gives
error: ‘const class clang::QualType’ has no member named ‘isAtomicType’
. (When applied only here, and also for other locations which was what I first tried as TBH theisa<AtomicType>
is something I plainly copy-pasted from other locations in this C++ file).