[all-commits] [llvm/llvm-project] 8056d9: [lldb][ClangExpressionParser] Implement ExternalSe...

Michael Buch via All-commits all-commits at lists.llvm.org
Tue Aug 20 10:43:07 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8056d92bc201906edbb27f4efa1cc80a18359880
      https://github.com/llvm/llvm-project/commit/8056d92bc201906edbb27f4efa1cc80a18359880
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2024-08-20 (Tue, 20 Aug 2024)

  Changed paths:
    M lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
    M lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    A lldb/test/Shell/Expr/TestAnonNamespaceParamFunc.cpp

  Log Message:
  -----------
  [lldb][ClangExpressionParser] Implement ExternalSemaSource::ReadUndefinedButUsed (#104817)

While parsing an expression, Clang tries to diagnose usage of decls
(with possibly non-external linkage) for which it hasn't been provided
with a definition. This is the case, e.g., for functions with parameters
that live in an anonymous namespace (those will have `UniqueExternal`
linkage, this is computed [here in
computeTypeLinkageInfo](https://github.com/llvm/llvm-project/blob/ea8bb4d633683f5cbfd82491620be3056f347a02/clang/lib/AST/Type.cpp#L4647-L4653)).
Before diagnosing such situations, Clang calls
`ExternalSemaSource::ReadUndefinedButUsed`. The intended use of this API
is to extend the set of "used but not defined" decls with additional
ones that the external source knows about. However, in LLDB's case, we
never provide `FunctionDecl`s with a definition, and instead rely on the
expression parser to resolve those symbols by linkage name. Thus, to
avoid the Clang parser from erroring out in these situations, this patch
implements `ReadUndefinedButUsed` which just removes the "undefined"
non-external `FunctionDecl`s that Clang found.

We also had to add an `ExternalSemaSource` to the `clang::Sema` instance
LLDB creates. We previously didn't have any source on `Sema`. Because we
add the `ExternalASTSourceWrapper` here, that means we'd also
technically be adding the `ClangExpressionDeclMap` as an
`ExternalASTSource` to `Sema`, which is fine because `Sema` will only be
calling into the `ExternalSemaSource` APIs (though nothing currently
strictly enforces this, which is a bit worrying).

Note, the decision for whether to put a function into `UndefinedButUsed`
is done in
[Sema::MarkFunctionReferenced](https://github.com/llvm/llvm-project/blob/ea8bb4d633683f5cbfd82491620be3056f347a02/clang/lib/Sema/SemaExpr.cpp#L18083-L18087).
The `UniqueExternal` linkage computation is done in
[getLVForNamespaceScopeDecl](https://github.com/llvm/llvm-project/blob/ea8bb4d633683f5cbfd82491620be3056f347a02/clang/lib/AST/Decl.cpp#L821-L833).

Fixes https://github.com/llvm/llvm-project/issues/104712



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list