Fix wrong expected output for default_in_statics.cpp/unsafe test and shared reference to mutable static errors#179
Fix wrong expected output for default_in_statics.cpp/unsafe test and shared reference to mutable static errors#179Copilot wants to merge 18 commits into
Conversation
static mut reference emission and remove test-driver suppression
static mut reference emission and remove test-driver suppressionconverter.cpp
converter.cppstatic mut reference emission in global array decay
| auto *sub_expr = expr->getSubExpr(); | ||
| auto emit_target = [&]() { | ||
| if (IsGlobalVar(sub_expr)) { | ||
| StrCat("(*(&raw", keyword_mut_); |
| StrCat(".cast_mut()"); | ||
| } | ||
| if (IsGlobalVar(sub_expr)) { | ||
| StrCat("(&raw", dest_pointee_const ? keyword::kConst : keyword_mut_); |
static mut reference emission in global array decayPushParen for raw-pointer wrapping
mut function-pointer checks
mut function-pointer checks|
@lucic71 please have a look |
|
@copilot woff2 and brunsli still don't compile: C++ code: Rust code currently generated: |
... Fixed in the latest commit. The root cause was in The fix checks // Before
StrCat(token::kRef);
if (IsMut(qual_type)) { StrCat(keyword_mut_); }
// After
if (IsGlobalVar(expr)) {
StrCat("&raw");
StrCat(IsMut(qual_type) ? keyword_mut_ : keyword::kConst);
} else {
StrCat(token::kRef);
if (IsMut(qual_type)) { StrCat(keyword_mut_); }
}This produces |
| const auto &frag = fragments[i]; | ||
| if (const auto *t = std::get_if<TextFragment>(&frag)) { | ||
| std::string text = t->text; | ||
| // If this text fragment ends with a lone '&' (reference operator, not |
There was a problem hiding this comment.
Doing string manipulation on the text fragments is fragile. Prefer adding new attributes in the IR if this change is necessary.
| expr->getType()->isFunctionPointerType()) { | ||
| StrCat(").is_none()"); | ||
| // Walk up through member accesses and array subscripts to find the root | ||
| // global var (file-scope or static-local). Any fn-ptr field access on a |
There was a problem hiding this comment.
This is not the right place to check against global variables. Prefer to propagate a flag from here to VisitVarDecl
| } | ||
| } | ||
|
|
||
| void Converter::ConvertGlobalVarBaseSuffix(clang::Expr *expr) { |
There was a problem hiding this comment.
This is not good. The logic here should go into VisitMemberExpr and VisitArraySubscriptExpr
Uh oh!
There was an error while loading. Please reload this page.