[all-commits] [llvm/llvm-project] c3ba6f: [Modules] Delay deserialization of preferred_name ...

Viktoriia Bakalova via All-commits all-commits at lists.llvm.org
Fri Jan 17 00:11:20 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c3ba6f378ef80d750e2278560c6f95a300114412
      https://github.com/llvm/llvm-project/commit/c3ba6f378ef80d750e2278560c6f95a300114412
  Author: Viktoriia Bakalova <115406782+VitaNuo at users.noreply.github.com>
  Date:   2025-01-17 (Fri, 17 Jan 2025)

  Changed paths:
    M clang/include/clang/AST/Attr.h
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Serialization/ASTReader.h
    M clang/include/clang/Serialization/ASTRecordReader.h
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTReaderDecl.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    M clang/test/Modules/preferred_name.cppm
    M clang/utils/TableGen/ClangAttrEmitter.cpp

  Log Message:
  -----------
  [Modules] Delay deserialization of preferred_name attribute at r… (#122726)

…ecord level.

This fixes the incorrect diagnostic emitted when compiling the following
snippet

```
// string_view.h
template<class _CharT>
class basic_string_view;

typedef basic_string_view<char> string_view;

template<class _CharT>
class
__attribute__((__preferred_name__(string_view)))
basic_string_view {
public:
    basic_string_view() 
    {
    }
};

inline basic_string_view<char> foo()
{
  return basic_string_view<char>();
}
// A.cppm
module;
#include "string_view.h"
export module A;

// Use.cppm
module;
#include "string_view.h"
export module Use;
import A;
```

The diagnostic is 
```
string_view.h:11:5: error: 'basic_string_view<char>::basic_string_view' from module 'A.<global>' is not present in definition of 'string_view' provided earlier
```

The underlying issue is that deserialization of the `preferred_name`
attribute triggers deserialization of `basic_string_view<char>`, which
triggers the deserialization of the `preferred_name` attribute again
(since it's attached to the `basic_string_view` template).
The deserialization logic is implemented in a way that prevents it from
going on a loop in a literal sense (it detects early on that it has
already seen the `string_view` typedef when trying to start its
deserialization for the second time), but leaves the typedef
deserialization in an unfinished state. Subsequently, the `string_view`
typedef from the deserialized module cannot be merged with the same
typedef from `string_view.h`, resulting in the above diagnostic.

This PR resolves the problem by delaying the deserialization of the
`preferred_name` attribute until the deserialization of the
`basic_string_view` template is completed. As a result of deferring, the
deserialization of the `preferred_name` attribute doesn't need to go on
a loop since the type of the `string_view` typedef is already known when
it's deserialized.



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