Skip to content

Commit 789a8bd

Browse files
chrysnthedataking
authored andcommitted
c2rust-exporter: Remove Atomics warning
As atomics are being implemented, these warnings are becoming wrong. Any operations on atomics that stay unimplmented will be caught more precisely at later translation stages.
1 parent f0859ed commit 789a8bd

3 files changed

+201
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From 2c18a0503e1f8ea41b8b94b5771b38a149f8171f Mon Sep 17 00:00:00 2001
2+
From: chrysn <[email protected]>
3+
Date: Wed, 8 Jun 2022 13:26:19 +0200
4+
Subject: [PATCH] C11 atomics: Add tag, move information over to Rust side
5+
6+
---
7+
c2rust-ast-exporter/src/AstExporter.cpp | 22 +++++++++++++---------
8+
c2rust-ast-exporter/src/ast_tags.hpp | 2 ++
9+
c2rust-transpile/src/c_ast/conversion.rs | 5 +++++
10+
3 files changed, 20 insertions(+), 9 deletions(-)
11+
12+
diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp
13+
index 56cce5c93..480a53390 100644
14+
--- a/c2rust-ast-exporter/src/AstExporter.cpp
15+
+++ b/c2rust-ast-exporter/src/AstExporter.cpp
16+
@@ -273,6 +273,8 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
17+
18+
void VisitVariableArrayType(const VariableArrayType *T);
19+
20+
+ void VisitAtomicType(const AtomicType *AT);
21+
+
22+
void VisitIncompleteArrayType(const IncompleteArrayType *T) {
23+
auto t = T->getElementType();
24+
auto qt = encodeQualType(t);
25+
@@ -2409,15 +2411,17 @@ void TypeEncoder::VisitVariableArrayType(const VariableArrayType *T) {
26+
27+
VisitQualType(t);
28+
}
29+
-//
30+
-//void TypeEncoder::VisitAtomicType(const AtomicType *AT) {
31+
-// std::string msg =
32+
-// "C11 Atomic types are not supported. Aborting.";
33+
-//// auto horse = AT->get
34+
-//// astEncoder->printError(msg, AT);
35+
-// AT->getValueType()->dump();
36+
-// abort();
37+
-//}
38+
+
39+
+void TypeEncoder::VisitAtomicType(const AtomicType *AT) {
40+
+ auto t = AT->getValueType();
41+
+ auto qt = encodeQualType(t);
42+
+
43+
+ encodeType(AT, TagAtomicType, [qt](CborEncoder *local) {
44+
+ cbor_encode_uint(local, qt);
45+
+ });
46+
+
47+
+ VisitQualType(t);
48+
+}
49+
50+
class TranslateConsumer : public clang::ASTConsumer {
51+
Outputs *outputs;
52+
diff --git a/c2rust-ast-exporter/src/ast_tags.hpp b/c2rust-ast-exporter/src/ast_tags.hpp
53+
index 9443d13fc..74e992b05 100644
54+
--- a/c2rust-ast-exporter/src/ast_tags.hpp
55+
+++ b/c2rust-ast-exporter/src/ast_tags.hpp
56+
@@ -142,6 +142,8 @@ enum TypeTag {
57+
TagComplexType,
58+
TagHalf,
59+
TagBFloat16,
60+
+
61+
+ TagAtomicType,
62+
};
63+
64+
enum StringTypeTag {
65+
diff --git a/c2rust-transpile/src/c_ast/conversion.rs b/c2rust-transpile/src/c_ast/conversion.rs
66+
index 45ea7bf81..b31339649 100644
67+
--- a/c2rust-transpile/src/c_ast/conversion.rs
68+
+++ b/c2rust-transpile/src/c_ast/conversion.rs
69+
@@ -826,6 +826,11 @@ impl ConversionContext {
70+
self.processed_nodes.insert(new_id, OTHER_TYPE);
71+
}
72+
73+
+ TypeTag::TagAtomicType => {
74+
+ // Next step in atomics implementation: Transfer to a CTypeKind
75+
+ panic!("C11 Atomics are not implemented in C2Rust yet.");
76+
+ }
77+
+
78+
t => panic!(
79+
"Type conversion not implemented for {:?} expecting {:?}",
80+
t, expected_ty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
From 6c941686f1a230d23685b2fcab104d88391f967a Mon Sep 17 00:00:00 2001
2+
From: chrysn <[email protected]>
3+
Date: Wed, 8 Jun 2022 13:18:08 +0200
4+
Subject: [PATCH] c2rust-exporter: Remove Atomics warnings
5+
6+
As atomics are being implemented, these warnings are becoming wrong. Any
7+
operations on atomics that stay unimplmented will be caught more
8+
precisely at later translation stages.
9+
---
10+
c2rust-ast-exporter/src/AstExporter.cpp | 54 -------------------------
11+
1 file changed, 54 deletions(-)
12+
13+
diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp
14+
index d5e9e7b68..56cce5c93 100644
15+
--- a/c2rust-ast-exporter/src/AstExporter.cpp
16+
+++ b/c2rust-ast-exporter/src/AstExporter.cpp
17+
@@ -189,24 +189,6 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
18+
astEncoder(ast) {}
19+
20+
void VisitQualType(const QualType &QT) {
21+
- if(isa<AtomicType>(QT)) {
22+
- // No printC11AtomicError available here and no location
23+
- // information either -- should better have been caught at the
24+
- // caller, but catching it here is still better than the
25+
- // nondescript error messages that would come later.
26+
- std::string msg = "C11 Atomics are not supported. No precise "
27+
- "location information available. Aborting.";
28+
-
29+
- auto &DiagEngine = Context->getDiagnostics();
30+
- // Prefix warnings with `c2rust`, so the user can distinguish
31+
- // our warning messages from those generated by clang itself.
32+
- const auto ID = DiagEngine.getCustomDiagID(DiagnosticsEngine::Error,
33+
- "c2rust: %0");
34+
- DiagEngine.Report(SourceLocation::getFromRawEncoding(0), ID).AddString(msg);
35+
-
36+
- abort();
37+
- }
38+
-
39+
if (!QT.isNull()) {
40+
auto s = QT.split();
41+
42+
@@ -1919,10 +1901,6 @@ class TranslateASTVisitor final
43+
// Use the type from the definition in case the extern was an incomplete
44+
// type
45+
auto T = def->getType();
46+
- if(isa<AtomicType>(T)) {
47+
- printC11AtomicError(def);
48+
- abort();
49+
- }
50+
51+
auto loc = is_defn ? def->getLocation() : VD->getLocation();
52+
53+
@@ -2006,12 +1984,6 @@ class TranslateASTVisitor final
54+
auto recordAlignment = 0;
55+
auto byteSize = 0;
56+
57+
- auto t = D->getTypeForDecl();
58+
- if(isa<AtomicType>(t)) {
59+
- printC11AtomicError(D);
60+
- abort();
61+
- }
62+
-
63+
auto loc = D->getLocation();
64+
std::vector<void *> childIds;
65+
if (def) {
66+
@@ -2084,12 +2056,6 @@ class TranslateASTVisitor final
67+
// They are used in actual code and accepted by compilers, so we cannot
68+
// exit early via code like `if (!D->isCompleteDefinition()) return true;`.
69+
70+
- auto t = D->getTypeForDecl();
71+
- if(isa<AtomicType>(t)) {
72+
- printC11AtomicError(D);
73+
- abort();
74+
- }
75+
-
76+
std::vector<void *> childIds;
77+
for (auto x : D->enumerators()) {
78+
childIds.push_back(x->getCanonicalDecl());
79+
@@ -2148,10 +2114,6 @@ class TranslateASTVisitor final
80+
81+
std::vector<void *> childIds;
82+
auto t = D->getType();
83+
- if(isa<AtomicType>(t)) {
84+
- printC11AtomicError(D);
85+
- abort();
86+
- }
87+
88+
auto record = D->getParent();
89+
const ASTRecordLayout &layout =
90+
@@ -2206,17 +2168,6 @@ class TranslateASTVisitor final
91+
cbor_encode_boolean(array, D->isImplicit());
92+
});
93+
94+
- if(isa<AtomicType>(typeForDecl)) {
95+
- // This case is especially checked as that's what happens when
96+
- // clang's stdatomic.h is traversed. Other callers of VisitQualType
97+
- // could get the same check to preserve the location information
98+
- // available in Decl but not in Type, but those are more likely not
99+
- // to be hit, and can fall back to the less descriptive error from
100+
- // inside there.
101+
- printC11AtomicError(D);
102+
- abort();
103+
- }
104+
-
105+
typeEncoder.VisitQualType(typeForDecl);
106+
107+
return true;
108+
@@ -2373,11 +2324,6 @@ class TranslateASTVisitor final
109+
CharSourceRange::getCharRange(E->getSourceRange()));
110+
}
111+
112+
- void printC11AtomicError(Decl *D) {
113+
- std::string msg = "C11 Atomics are not supported. Aborting.";
114+
- printError(msg, D);
115+
- }
116+
-
117+
void printError(std::string Message, Decl *D) {
118+
auto DiagBuilder =
119+
getDiagBuilder(D->getLocation(), DiagnosticsEngine::Error);

c2rust-ast-exporter/src/AstExporter.cpp

+2-23
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
365365
}
366366
}();
367367
// All the SVE types present in Clang 10 are 128-bit vectors
368-
// (see `AArch64SVEACLETypes.def`), so we can divide 128
368+
// (see `AArch64SVEACLETypes.def`), so we can divide 128
369369
// by their element size to get element count.
370370
auto ElemCount = 128 / Context->getTypeSize(ElemType);
371371
#endif // CLANG_VERSION_MAJOR >= 11
@@ -405,7 +405,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
405405
// Constructed as a consequence of the conversion of
406406
// built-in to normal vector types.
407407
case BuiltinType::Float16: return TagHalf;
408-
case BuiltinType::Half: return TagHalf;
408+
case BuiltinType::Half: return TagHalf;
409409
#if CLANG_VERSION_MAJOR >= 11
410410
case BuiltinType::BFloat16: return TagBFloat16;
411411
#endif
@@ -1937,10 +1937,6 @@ class TranslateASTVisitor final
19371937
// Use the type from the definition in case the extern was an incomplete
19381938
// type
19391939
auto T = def->getType();
1940-
if (isa<AtomicType>(T)) {
1941-
printC11AtomicError(def);
1942-
abort();
1943-
}
19441940

19451941
auto loc = is_defn ? def->getLocation() : VD->getLocation();
19461942

@@ -2025,10 +2021,6 @@ class TranslateASTVisitor final
20252021
auto byteSize = 0;
20262022

20272023
auto t = D->getTypeForDecl();
2028-
if (isa<AtomicType>(t)) {
2029-
printC11AtomicError(D);
2030-
abort();
2031-
}
20322024

20332025
auto loc = D->getLocation();
20342026
std::vector<void *> childIds;
@@ -2103,10 +2095,6 @@ class TranslateASTVisitor final
21032095
// exit early via code like `if (!D->isCompleteDefinition()) return true;`.
21042096

21052097
auto t = D->getTypeForDecl();
2106-
if (isa<AtomicType>(t)) {
2107-
printC11AtomicError(D);
2108-
abort();
2109-
}
21102098

21112099
std::vector<void *> childIds;
21122100
for (auto x : D->enumerators()) {
@@ -2166,10 +2154,6 @@ class TranslateASTVisitor final
21662154

21672155
std::vector<void *> childIds;
21682156
auto t = D->getType();
2169-
if (isa<AtomicType>(t)) {
2170-
printC11AtomicError(D);
2171-
abort();
2172-
}
21732157

21742158
auto record = D->getParent();
21752159
const ASTRecordLayout &layout =
@@ -2384,11 +2368,6 @@ class TranslateASTVisitor final
23842368
CharSourceRange::getCharRange(E->getSourceRange()));
23852369
}
23862370

2387-
void printC11AtomicError(Decl *D) {
2388-
std::string msg = "C11 Atomics are not supported. Aborting.";
2389-
printError(msg, D);
2390-
}
2391-
23922371
void printError(std::string Message, Decl *D) {
23932372
auto DiagBuilder =
23942373
getDiagBuilder(D->getLocation(), DiagnosticsEngine::Error);

0 commit comments

Comments
 (0)