Skip to content

Add testing for C decl source range extraction#1622

Open
fw-immunant wants to merge 5 commits intofw/c-decls-ifdefsfrom
fw/c-decls-test
Open

Add testing for C decl source range extraction#1622
fw-immunant wants to merge 5 commits intofw/c-decls-ifdefsfrom
fw/c-decls-test

Conversation

@fw-immunant
Copy link
Contributor

Includes some other minor cleanups made on the way.

@fw-immunant fw-immunant changed the title Add testing for C decl source range Add testing for C decl source range extraction Feb 25, 2026
@fw-immunant fw-immunant requested a review from kkysen February 25, 2026 19:52
c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]);
c2rust_transpile::transpile(
TranspilerConfig {
emit_c_decl_map: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just enable this for everything in fn config? And then refactor the non-snapshot part of fn transpile/fn transpile_snapshot into a shared function, because they're basically both the same except for the end that does the snapshot testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've factored out the shared code, but setting emit_c_decls_json for all snapshots generates a bunch of irrelevant output files, so I think it's better to only set it when we actually want that output.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with some extra .gitignored output files? This adds some more testing at what is IMO negligible cost (some extra ignored files).

@kkysen kkysen self-requested a review February 26, 2026 23:22
}

extern "C" {
// Safety: Not thread-safe; must not be called multiple times concurrently.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Safety: Not thread-safe; must not be called multiple times concurrently.
/// # Safety
///
/// Not thread-safe; must not be called multiple times concurrently.

Comment on lines +17 to +33
anotherfunc(void)
{
int var = 0;
return 4 + var;
}
int
funcholdingdefine(void)
{
#define FOO 4000+50
return FOO;
}
// comment before multiple decl
int a1, a2, a3;
void forwarddeclbeforeotherdef(int x);
void funcafterdecl(int n) {}
/*real defn*/
void forwarddeclbeforeotherdef(int x) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
anotherfunc(void)
{
int var = 0;
return 4 + var;
}
int
funcholdingdefine(void)
{
#define FOO 4000+50
return FOO;
}
// comment before multiple decl
int a1, a2, a3;
void forwarddeclbeforeotherdef(int x);
void funcafterdecl(int n) {}
/*real defn*/
void forwarddeclbeforeotherdef(int x) { }
another_func(void)
{
int var = 0;
return 4 + var;
}
int
func_holding_define(void)
{
#define FOO 4000+50
return FOO;
}
// comment before multiple decl
int a1, a2, a3;
void forward_decl_before_other_def(int x);
void func_after_decl(int n) {}
/*real defn*/
void forward_decl_before_other_def(int x) { }

Was there a reason these names didn't have separators? It's pretty hard to read without them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants