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

Check for C11 atomics in and around VisitQualType #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
astEncoder(ast) {}

void VisitQualType(const QualType &QT) {
if(isa<AtomicType>(QT)) {
Copy link
Contributor

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().

Copy link
Contributor Author

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 the isa<AtomicType> is something I plainly copy-pasted from other locations in this C++ file).

Copy link
Contributor

Choose a reason for hiding this comment

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

This check needs to be moved inside the if (!QT.isNull()) { conditional below; otherwise we get an internal Clang abort doing isa<AtomicType>(QT) when QT has a null inner pointer.

// 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();

Expand Down Expand Up @@ -2188,6 +2206,17 @@ class TranslateASTVisitor final
cbor_encode_boolean(array, D->isImplicit());
});

if(isa<AtomicType>(typeForDecl)) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Expand Down