Files
clang-p2996/clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml
Victor Campos 85fdf50146 [Multilib] Custom flags YAML parsing (#122903)
This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
    MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
    - Name: io-none
    - Name: io-semihosting
      MacroDefines: [SEMIHOSTING]
    - Name: io-linux-syscalls
      MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=<string>`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D<string>``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
2025-01-15 10:11:39 +00:00

134 lines
3.0 KiB
YAML

# RUN: split-file %s %t
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/multilib-without-macro-defines.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/multilib-with-macro-defines.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s
# CHECK-NOT: error:
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/missing-flag-name.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-MISSING-FLAG-NAME
# CHECK-MISSING-FLAG-NAME: error: custom flag requires a name
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/missing-flag-values.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-MISSING-FLAG-VALUES
# CHECK-MISSING-FLAG-VALUES: error: custom flag must have at least one value
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/missing-flag-value-default.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-MISSING-FLAG-VALUE-DEFAULT
# CHECK-MISSING-FLAG-VALUE-DEFAULT: error: custom flag must have a default value
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/missing-flag-value-name.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-MISSING-FLAG-VALUE-NAME
# CHECK-MISSING-FLAG-VALUE-NAME: error: custom flag value requires a name
# RUN: %clang --target=arm-none-eabi --multi-lib-config=%t/duplicate-flag-value-name.yaml %s -### -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-DUPLICATE-FLAG-VALUE-NAME
# CHECK-DUPLICATE-FLAG-VALUE-NAME: error: duplicate custom flag value name: "value-name"
# CHECK-DUPLICATE-FLAG-VALUE-NAME-NEXT: - Name: value-name
#--- multilib-without-macro-defines.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Name: flag
Values:
- Name: a
- Name: b
Default: a
#--- multilib-with-macro-defines.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Name: flag
Values:
- Name: a
MacroDefines: [FEATURE_A]
- Name: b
MacroDefines: [FEATURE_B]
Default: a
#--- missing-flag-name.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Values:
- Name: a
Default: a
#--- missing-flag-values.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Name: flag
Values:
Default: a
#--- missing-flag-value-default.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Name: flag
Values:
- Name: a
Default:
#--- missing-flag-value-name.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=a]
Flags:
- Name: flag
Values:
- Name:
Default: a
#--- duplicate-flag-value-name.yaml
---
MultilibVersion: 1.0
Variants:
- Dir: libc
Flags: [-fmultilib-flag=value-name]
Flags:
- Name: a
Values:
- Name: value-name
- Name: value-a
Default: value-name
- Name: b
Values:
- Name: value-name
Default: value-name