Skip to content

Comment out compiler builtins#304

Open
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:builtin
Open

Comment out compiler builtins#304
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:builtin

Conversation

@davispuh

Copy link
Copy Markdown

Consider C header like:

#define va_copy __builtin_va_copy
#define ALIGNOF(TYPE)  _Alignof (TYPE)
#define __unused  __attribute__((__unused__))
#define __noreturn  __attribute__((__noreturn__))
#define STATIC_ASSERT  _Static_assert
#define CONST  const
#define STATIC  static
#define __volatile  volatile

Currently dsep would produce:

enum va_copy = __builtin_va_copy;

Which fails to compile:

Error: undefined identifier `__builtin_va_copy`
enum va_copy = __builtin_va_copy;

When this PR is applied together with #303
Then result will be:

// FIXME: enum va_copy = __builtin_va_copy;
// FIXME: alias ALIGNOF = _Alignof;
// FIXME: enum __unused = __attribute__(__unused__);
// FIXME: enum __noreturn = __attribute__(__noreturn__);
// FIXME: enum STATIC_ASSERT = _Static_assert;
// FIXME: enum CONST = const;
// FIXME: enum STATIC = static;

Copilot AI review requested due to automatic review settings March 19, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates macro translation output so that macros which expand to C compiler builtins/keywords/attributes (and therefore generate invalid D code) are emitted as commented-out // FIXME: lines instead of uncompilable declarations, aligning with the behavior introduced in #303.

Changes:

  • Detect compiler builtins (e.g., __builtin_*) and _Alignof in function-alias macro translation and prefix the generated alias with // FIXME:.
  • Detect keyword/attribute-like macro values (e.g., const, static, _Static_assert, __attribute__*) in alias/const macro translation and prefix the generated declaration with // FIXME:.
  • Avoid repeated translation of the same macro expression by storing the translated value once.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dstep/translator/MacroDefinition.d
Comment thread dstep/translator/MacroDefinition.d Outdated

@jacob-carlborg jacob-carlborg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There's no test added.

Consider C header like:
```
 #define va_copy __builtin_va_copy
 #define ALIGNOF(TYPE)  _Alignof (TYPE)
 #define __unused  __attribute__((__unused__))
 #define __noreturn  __attribute__((__noreturn__))
 #define STATIC_ASSERT  _Static_assert
 #define CONST  const
 #define STATIC  static
 #define __volatile  volatile
```

This commit implements commenting out such compiler builtins with `// FIXME:` prefix.
@davispuh

Copy link
Copy Markdown
Author

I added a test.

@davispuh davispuh mentioned this pull request Jun 27, 2026
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