Skip to content

[HIPIFY][#2402] Transitive preceding includes for deeply nested recursive headers #2507

Description

@ranapratap55

Context

Raised by @emankov in 2402

Looks like the collectPrecedingIncludes only scans the immediate parentPath.
What about deeply nested headers?

With #2402

When hipify-clang recursively hipifies local headers, collectPrecedingIncludes only scans the immediate parent file to inject before the target header. This is correct for one level of nesting but breaks for deeper chains.

Failure scenario

main.cu: 
#include "base_types.h" // defines base_t
#include "module_a.h"

module_a.h:
#include "module_b.h" // uses base_t but never explicitly includes base_types.h

module_b.h:
base_t compute() // fails: base_t undefined during standalone hipification
{ ... } 

collectPrecedingIncludes(module_a.h, module_b.h) scans module_a.h, finds nothing before module_b.h, injects nothing. module_b.h fails to compile because base_t is not available.

A transitive collection of all ancestors and injecting everything will cause redefinition errors if two ancestor files both define the same symbol and injecting both breaks correct code.

Possible Fix

Extend from {hdr, parentPath} to {hdr, vector<parentChain>}. When collecting preceding includes for a header, check ancestor chain and collect only includes that appear before the nearest ancestor that explicitly includes the target. This solves the over-injection issue.

Related to #2402

Metadata

Metadata

Labels

enhancementEnhancementfeatureFeature request or implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions