Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Avoid pure macro collisions in LLVM attribute detection - #9074

Merged
Damyan Pepper (damyanp) merged 6 commits into
microsoft:mainfrom
ruiji-shi:user/ruishi/clangfix-pure-macro
Oct 30, 2026
Merged

Damyan Pepper (damyanp) merged 6 commits into
microsoft:mainfrom
ruiji-shi:user/ruishi/clangfix-pure-macro

Conversation

@ruiji-shi

@ruiji-shi ruishi_msft (ruiji-shi) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Avoid pure macro collisions in LLVM attribute detection

Windows PDB headers can define pure as = 0. If such a header is included first, Clang expands that macro inside __has_attribute(pure) and reports:

builtin feature check macro requires a parenthesized identifier
missing ')' after '='

Clang and GCC recognize __pure__ as an equivalent spelling of the attribute. Using that reserved spelling avoids expanding the caller's pure macro. The existing LLVM_READONLY definition already emits __attribute__((__pure__)), so the emitted attribute and runtime behavior are unchanged.

Validation

Local OS build with MSVC and Clang-cl.

Query __has_attribute(__pure__) so a caller's pure macro is not expanded into the builtin feature check. Keep the existing LLVM_READONLY attribute unchanged.

Add a SupportTests regression for the PDB-style pure macro collision.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Remove the standalone CompilerTest.cpp regression and its SupportTests registration as requested. The net change against upstream remains only the __has_attribute(__pure__) query.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
@ruiji-shi
ruishi_msft (ruiji-shi) marked this pull request as ready for review October 27, 2026 18:54
Copilot AI balanced review requested due to automatic review settings October 27, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The include-order fix needs an automated regression test that fails with the original spelling.

1 open issue
What changed in this PR

This PR fixes an include-order compatibility issue in LLVM’s attribute detection without changing the attribute emitted by LLVM_READONLY.

Changes:

  • Uses __has_attribute(__pure__) to avoid collisions with a caller-defined pure macro.
  • Preserves the existing read-only attribute behavior.

Seagulls asking "TEST CASE?"

Please add an automated regression test covering the conflicting macro before header inclusion.

File Description
include/​llvm/​Support/​Compiler.h Uses the reserved attribute spelling to avoid macro expansion.

Review effort: Balanced

#endif

#if __has_attribute(pure) || defined(__GNUC__)
#if __has_attribute(__pure__) || defined(__GNUC__)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is fixed by adding a new test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm actually of the opinion that a test is unnecessary here: it's very unlikely that someone sees __pure__ in two places and goes "nah, one of them should be pure instead" and revert your change.

But, up to you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make sense, removed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
Copilot AI balanced review requested due to automatic review settings October 27, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrow fix preserves attribute semantics and includes regression coverage for the reported macro collision.

1 open issue

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
Copilot AI balanced review requested due to automatic review settings October 27, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized fix preserves attribute semantics and includes regression coverage for the macro collision, with no unresolved findings.

1 open issue

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 08f9ee45-220b-41eb-a6ff-c21beb0fcdf9
Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the macro-safe attribute detection change.

1 open issue

Review effort: Balanced

@damyanp

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@damyanp

Damyan Pepper (damyanp) commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Can you explain some more about the motivation for making this change please? What scenario is this addressing? Has a similar change been made in upstream llvm?

@alsepkow Alex Sepkowski (alsepkow) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Assuming you will address Damyan Pepper (@damyanp) s concern

We should also make this change in LLVM. You can help justify the change there with this documentation that suggests the same: https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute

@ruiji-shi

Copy link
Copy Markdown
Contributor Author

Can you explain some more about the motivation for making this change please? What scenario is this addressing? Has a similar change been made in upstream llvm?

Yes, there is an error in one of the OS.2020 directory, it fails during Clang PCH compilation, where that PCH include xxx\dxil\include\llvm\Support\Compiler.h:162

The root cause is that the pure was defined as = 0 in the PCH within another pdb.h included earlier than Compiler.h. That macro leaks into subsequent LLVM includes, turning __has_attribute(pure) into invalid __has_attribute(= 0).

There is a way to fix in PCH and not let the pure definition get leaked. However, after discussion with Alex offline, it is better to fix with the change in this PR and upstream too in LLVM. The reason is that someone can still defines pure in another header and breaks the build. And __pure__ syntax is also better to avoid collision as shared by Alex https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute. Feel free to let me know if any question.

I keep this PR since LLVM does not ship into this DXC. I will create another PR in LLVM so future modern DXC can consume it.

@damyanp
Damyan Pepper (damyanp) merged commit f9fc72a into microsoft:main Oct 30, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants