Skip to content

Conversation

@bmwalters
Copy link

split into patches for review:

  • clang-21: fix DTST->getIdentifier()
  • clang-21: remove TypeSpecWithTemplate
  • clang-21: OpenCLKernelAttr --> DeviceKernelAttr
  • clang-21: avoid deprecated FileManager::getDirectory
    • this existed in llvm 16 so is not ifdef'd
  • clang-21: call CompilerInvocation::getTargetOpts

Depends on #285 and #287 to get a working build.

I chose not to stack on them since the patches commute.

- **Line 7086-7089**: Stores `NestedNameSpecifier *NNS` and `const IdentifierInfo *Name` as separate membe
rs
- **Line 7098-7099**: Provides `getQualifier()` and `getIdentifier()` methods

- **Line 7258**: Now stores a single `DependentTemplateStorage Name` member (instead of separate NNS and I
dentifierInfo)
- **Line 7266-7268**: Provides `getDependentTemplateName()` method that returns `const DependentTemplateSt
orage&`
- **Removed**: `getQualifier()` and `getIdentifier()` methods are gone

The `DependentTemplateStorage` class (defined in TemplateName.h:582-621) provides:
- `getQualifier()` → returns `NestedNameSpecifier*`
- `getName()` → returns `IdentifierOrOverloadedOperator`

The `IdentifierOrOverloadedOperator` struct (TemplateName.h:545-572) provides:
- `getIdentifier()` → returns `const IdentifierInfo*`

The failing code at CommonRenameClassRewriteVisitor.h:313:
```cpp
const IdentifierInfo *IdInfo = DTST->getIdentifier();
```

Should be changed to:
```cpp
const IdentifierInfo *IdInfo = DTST->getDependentTemplateName().getName().getIdentifier();
```

This chains the new API calls:
1. `getDependentTemplateName()` returns the `DependentTemplateStorage`
2. `getName()` returns the `IdentifierOrOverloadedOperator`
3. `getIdentifier()` returns the `const IdentifierInfo*`
The enum has **6 values**:
- Line 79-102: `Identifier`, `Namespace`, `NamespaceAlias`, `TypeSpec`, **`TypeSpecWithTemplate`**, `Globa
l`, `Super`
- Line 52-56: Storage enum includes `StoredTypeSpec = 2` and `StoredTypeSpecWithTemplate = 3`

The enum has **5 values** (one removed):
- Line 78-97: `Identifier`, `Namespace`, `NamespaceAlias`, `TypeSpec`, `Global`, `Super`
- **`TypeSpecWithTemplate` was removed**
- Line 52-55: Storage enum only has `StoredTypeSpec = 2` (no `StoredTypeSpecWithTemplate`)

In LLVM 21, the distinction between `TypeSpec` and `TypeSpecWithTemplate` was eliminated. The `template` k
eyword information is now stored differently (likely in the `TypeLoc` or associated location information r
ather than in the specifier kind).

Since both cases were doing the same thing (calling `TraverseTypeLoc`), and LLVM 21 merged them into a sin
gle `TypeSpec` case, simply removing the `TypeSpecWithTemplate` case is the correct fix. The functionality
 remains the same because type specs with or without template keywords now both use the `TypeSpec` enum va
lue.
The following kernel attributes existed:
- `OpenCLKernelAttr` - for OpenCL kernels
- `NVPTXKernelAttr` - for NVIDIA PTX kernels
- `SYCLKernelAttr` - for SYCL kernels

The attribute system was refactored:
- **`OpenCLKernelAttr` was removed**
- **`NVPTXKernelAttr` was removed**
- Replaced with a unified `DeviceKernelAttr` attribute
- `SYCLKernelEntryPointAttr` exists for SYCL-specific entry points

LLVM 21 consolidated the various kernel attributes (`OpenCLKernelAttr`, `NVPTXKernelAttr`, etc.) into a si
ngle unified `DeviceKernelAttr` that works across different device programming models (OpenCL, CUDA, etc.)
.

This change reflects the consolidation of kernel attributes in LLVM 21. The `DeviceKernelAttr` now covers
what `OpenCLKernelAttr` (and other kernel attributes) used to represent.

**Purpose**: The code is checking if a function is a kernel function that should not be removed even if it
 appears unused, since kernel functions are entry points called by the runtime. The new `DeviceKernelAttr`
 serves this same purpose across all device programming models.
The deprecated `getDirectory()` method that returned `ErrorOr<const DirectoryEntry *>` was removed in LLVM 21. The migration path is to use `getOptionalDirectoryRef()` which returns an `OptionalDirectoryEntryRef`.

**Why this works**:
- The original code checks the boolean value of the `ErrorOr` result (true if directory exists, false otherwise)
- The new code checks the boolean value of the `OptionalDirectoryEntryRef` (true if directory exists, false otherwise)
- Both support implicit conversion to bool in the same way, so the logic remains identical
**LLVM 20 & 21 (CompilerInvocation.h:80)**:
- `TargetOpts` is a **protected** member in `CompilerInvocationBase`
- Direct access like `.TargetOpts` is not allowed from outside the class

**Solution**: Use the public getter method `getTargetOpts()` instead of direct member access

**LLVM 20 (TargetInfo.h:305-306)**:
- Signature: `CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr<TargetOptions> &Opts)`
- Accepts a `std::shared_ptr<TargetOptions>` (shared pointer)

**LLVM 21 (TargetInfo.h:316-317)**:
- Signature: `CreateTargetInfo(DiagnosticsEngine &Diags, TargetOptions &Opts)`
- Accepts a `TargetOptions &` (reference)

1. The code was directly accessing the protected member `TargetOpts` instead of using the public getter
2. The `CreateTargetInfo` API changed from accepting a `shared_ptr` to accepting a reference

**Why this works**:
1. `getTargetOpts()` is a public method (defined at line 250 in `CompilerInvocation`) that returns `TargetOptions &`
2. This matches the new LLVM 21 signature that expects `TargetOptions &` instead of `std::shared_ptr<TargetOptions>`
3. The getter dereferences the shared_ptr internally (`return *TargetOpts`), providing the reference that the new API needs
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.

1 participant