Skip to content

Generate pointer-valued macro constants#3379

Open
tamird wants to merge 1 commit into
rust-lang:mainfrom
tamird:fix-pointer-macro-constants
Open

Generate pointer-valued macro constants#3379
tamird wants to merge 1 commit into
rust-lang:mainfrom
tamird:fix-pointer-macro-constants

Conversation

@tamird
Copy link
Copy Markdown
Contributor

@tamird tamird commented May 27, 2026

The Clang macro fallback can evaluate macro forms that cexpr cannot
parse, but it discards pointer-valued expressions. Emit data pointer
macros as raw Rust pointer constants. Keep dependent expressions
eligible for fallback evaluation.

Materialize pointer macro types from a final fallback parse so
deferred type resolution does not retain cursors invalidated by a
later reparse.

Related to #3347.

@tamird
Copy link
Copy Markdown
Contributor Author

tamird commented May 27, 2026

cc @metaspace @ojeda

The Clang macro fallback can evaluate macro forms that cexpr cannot
parse, but it discards pointer-valued expressions. Emit data pointer
macros as raw Rust pointer constants. Keep dependent expressions
eligible for fallback evaluation.

Materialize pointer macro types from a final fallback parse so
deferred type resolution does not retain cursors invalidated by a
later reparse.

Related to rust-lang#3347.
@tamird tamird force-pushed the fix-pointer-macro-constants branch from ee2d27d to dd174a8 Compare May 27, 2026 23:21
@tamird
Copy link
Copy Markdown
Contributor Author

tamird commented May 27, 2026

r? @emilio

@ojeda
Copy link
Copy Markdown
Contributor

ojeda commented May 28, 2026

It could be nice to split in two commits, to see how the test changes -- from a quick test against mainline I see:

+pub const BEFORE_DECL: *mut later = 3u64 as usize as *mut later;
+pub const CONST_PTR: *const later = 4u64 as usize as *const later;
+pub const TYPEDEF_PTR: *mut later = 5u64 as usize as *mut later;
+pub const MAP_FAILED: *mut ::std::os::raw::c_void = 18446744073709551615u64 as usize
+    as *mut ::std::os::raw::c_void;
+pub const MAP_FAILED_ALIAS: *mut ::std::os::raw::c_void = 18446744073709551615u64
+    as usize as *mut ::std::os::raw::c_void;
 pub const MAP_FAILED_EQUALS_ITSELF: u32 = 1;
 pub const REDEFINED_FROM_INT: u32 = 1;
-pub const REDEFINED_ALIAS: u32 = 1;
+pub const REDEFINED_ALIAS: *mut ::std::os::raw::c_void = 2u64 as usize
+    as *mut ::std::os::raw::c_void;

Is that the expected change here?

I am surprised there was no other test that needed an update for the REDEFINED_ALIAS case.

(A couple surprising but pre-existing issues discussed elsewhere IIRC are the value of REDEFINED_FROM_INT and the type of e.g. MAP_FAILED_EQUALS_ITSELF)

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