Skip to content

[clang-include-cleaner] __attribute__((__cleanup__())) function declaration detection doesn't work if hidden behind a macro #140212

@DaanDeMeyer

Description

@DaanDeMeyer

In systemd, we define the following macro:

#define _cleanup_(x) __attribute__((__cleanup__(x)))

This breaks the integration for __cleanup__ that I added in #138669.

The problem is caused by this bit of code in Analysis.cpp:

      auto FID = SM.getFileID(SM.getSpellingLoc(Loc));
      if (FID != SM.getMainFileID() && FID != SM.getPreambleFileID())
        return;

The location passed in VisitCleanupAttr() doesn't map to either the main file ID or the preamble file ID.

I assume this happens because we only have a location for the cleanup attribute which is mapped back to the macro. But we don't seem to have a location for the function decl that's in the cleanup macro. Otherwise I'd pass in that location and expect things to work but that doesn't seem to be an option.

Happy to work on a fix, I just don't have a clue what the best way to fix this would be.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions