C: Doesn't deal with macro nonsense #612

Open
opened 2025-10-08 19:13:03 +02:00 by bjackman · 2 comments

Most nontrivial C projects have some macros that don't look like normal C syntax, e.g. here is some LInux kernel code:

/* irq_work to run mmap_read_unlock() in irq_work */
struct mmap_unlock_irq_work {
	struct irq_work irq_work;
	struct mm_struct *mm;
};

DECLARE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work);

It appears that mergiraf isn't able to take this into account:

❯❯  mergiraf solve arch/x86/include/asm/asi.h
WARN Error while resolving conflicts: parse error at 145:0..145:47, starting with: `DECLARE_PER_CPU_ALIGNED(struct a`
WARN Full structured merge failed: parse error at 140:23..140:28, starting with: `pgd_t`
INFO 1 conflict(s) remaining.

(The actual code I'm compiling here isn't public right now, sorry).

Is this expected? I assume Mergiraf is fundamentally unable to deal with [ab]use of the preprocessor in this style? Maybe this isn't surprising but it should probably be mentioned up-front on the language support docs page.

Most nontrivial C projects have some macros that don't look like normal C syntax, e.g. here is some LInux kernel code: ```C /* irq_work to run mmap_read_unlock() in irq_work */ struct mmap_unlock_irq_work { struct irq_work irq_work; struct mm_struct *mm; }; DECLARE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work); ``` It appears that mergiraf isn't able to take this into account: ``` ❯❯ mergiraf solve arch/x86/include/asm/asi.h WARN Error while resolving conflicts: parse error at 145:0..145:47, starting with: `DECLARE_PER_CPU_ALIGNED(struct a` WARN Full structured merge failed: parse error at 140:23..140:28, starting with: `pgd_t` INFO 1 conflict(s) remaining. ``` (The actual code I'm compiling here isn't public right now, sorry). Is this expected? I assume Mergiraf is fundamentally unable to deal with [ab]use of the preprocessor in this style? Maybe this isn't surprising but it should probably be mentioned up-front on the language support docs page.
Owner

Yes, that's a known limitation of the tree-sitter parser, see #102.

but it should probably be mentioned up-front on the language support docs page.

That's a good idea, a PR would be very welcome:)

Yes, that's a known limitation of the tree-sitter parser, see https://codeberg.org/mergiraf/mergiraf/issues/102. > but it should probably be mentioned up-front on the language support docs page. That's a good idea, a PR would be very welcome:)
Owner

Also, the warning message is not ideal: I would expect a single warning message mentioning the parse failure, not one per attempt (although they are indeed different, and it's legitimate for the first one to fail when the second suceeds… not easy).

Also, the warning message is not ideal: I would expect a single warning message mentioning the parse failure, not one per attempt (although they are indeed different, and it's legitimate for the first one to fail when the second suceeds… not easy).
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#612
No description provided.