Skip to content

[clang][Sema] theoretical ABI break in LLVM 20.1.1 #133955

Open
@isuckatcs

Description

@isuckatcs

In LLVM 20.1.0 we have the following Sema class.

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 LLVM 20.1.1 this definition is changed the way below.

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.

Normally this ABI break is the part of libclangSema.a, however we also have libclang-cpp.so, which collects all of the static libraries of clang and makes it possible to link against them dynamically. If an application is linked against clang dynamically, then according to the standard libclang-cpp.so.20.1.1 is not compatible with libclang-cpp.so.20.1.

I'm not sure if there are compilers taking advantage of this, but if they do, the resulting libclang-cpp.so might not be ABI compatible with it's previous release, as fields might have different offsets within the object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary Interfaceclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    Projects

    Status

    Needs Fix

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions