Issue 133955
Summary [libclang] Theoretical ABI break in `libclang.so` 20.1.1
Labels clang:as-a-library
Assignees
Reporter isuckatcs
    In `libclang.so.20.1.0` we have the following `Sema` class.
```c++
class Sema final : public SemaBase {
  ...

private:
  /// Function or variable declarations to be checked for whether the deferred
  /// diagnostics should be emitted.
  llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags;

  /// Map of current shadowing declarations to shadowed declarations. Warn if
  /// it looks like the user is trying to modify the shadowing declaration.
  llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;

  ...
};
```

In `libclang.so.20.1.1` this definition is changed the way below.

```c++
class Sema final : public SemaBase {
  ...

public:

  ...

  /// Function or variable declarations to be checked for whether the deferred
  /// diagnostics should be emitted.
  llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags;

private:
  

  /// Map of current shadowing declarations to shadowed declarations. Warn if
  /// it looks like the user is trying to modify the shadowing declaration.
  llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;

  ...
};
```

In other words, `DeclsToCheckForDeferredDiags` is made `public` in 20.1.1, when it was `private` in 20.1.0.

Until C++23 the C++ standard said the following about this.
> [Note: Non-static data members of a (non-union) class with the same access control (11.9) and non-zero
> size (6.7.2) are allocated so that later members have higher addresses within a class object. **The order of
> allocation of non-static data members with different access control is unspecified**.
>
> N4849 § 11.4 19

With C++23 however this restriction was removed though.
> [Note 8 : Non-variant non-static data members of non-zero size (6.7.2) are allocated so that later members 
> have higher addresses within a class object (7.6.9).
>
> N4950 § 11.4.1 20

LLVM is still compiled targeting the C++17 standard, which means, the first quote of the standard applies and compilers have the right to change the field order of `Sema` IIUC. I'm not sure if there are compilers taking advantage of this, but if they do, the resulting `libclang.so` will not be ABI compatible with it's previous release.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to