113 changes: 81 additions & 32 deletions clang-tools-extra/test/clang-doc/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
enum Color {
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
Red, ///< Red
Green, ///< Green
Blue ///< Blue
Red, ///< Comment 1
Green, ///< Comment 2
Blue ///< Comment 3
};

// MD-INDEX: ## Enums
Expand All @@ -34,23 +34,29 @@ enum Color {
// MD-INDEX: | Blue |
// MD-INDEX: **brief** For specifying RGB colors

// HTML-INDEX: <h2 id="Enums">Enums</h2>
// HTML-INDEX: <h3 id="{{([0-9A-F]{40})}}">enum Color</h3>
// HTML-INDEX: <li>Red</li>
// HTML-INDEX: <li>Green</li>
// HTML-INDEX: <li>Blue</li>
// HTML-INDEX: <th colspan="3">enum Color</th>
// HTML-INDEX: <td>Red</td>
// HTML-INDEX: <td>0</td>
// HTML-INDEX: <p> Comment 1</p>
// HTML-INDEX: <td>Green</td>
// HTML-INDEX: <td>1</td>
// HTML-INDEX: <p> Comment 2</p>
// HTML-INDEX: <td>Blue</td>
// HTML-INDEX: <td>2</td>
// HTML-INDEX: <p> Comment 3</p>

/**
* @brief Shape Types
*/
enum class Shapes {
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
/// Circle

/// Comment 1
Circle,
/// Rectangle
/// Comment 2
Rectangle,
/// Triangle
/// Comment 3
Triangle
};
// MD-INDEX: | enum class Shapes |
Expand All @@ -60,10 +66,17 @@ enum class Shapes {
// MD-INDEX: | Triangle |
// MD-INDEX: **brief** Shape Types

// HTML-INDEX: <h3 id="{{([0-9A-F]{40})}}">enum class Shapes</h3>
// HTML-INDEX: <li>Circle</li>
// HTML-INDEX: <li>Rectangle</li>
// HTML-INDEX: <li>Triangle</li>
// HTML-INDEX: <th colspan="3">enum class Shapes</th>
// HTML-INDEX: <td>Circle</td>
// HTML-INDEX: <td>0</td>
// HTML-INDEX: <p> Comment 1</p>
// HTML-INDEX: <td>Rectangle</td>
// HTML-INDEX: <td>1</td>
// HTML-INDEX: <p> Comment 2</p>
// HTML-INDEX: <td>Triangle</td>
// HTML-INDEX: <td>2</td>
// HTML-INDEX: <p> Comment 3</p>



class Animals {
Expand All @@ -76,18 +89,25 @@ class Animals {
enum AnimalType {
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
Dog, /// Man's best friend
Cat, /// Man's other best friend
Iguana /// A lizard
Dog, ///< Man's best friend
Cat, ///< Man's other best friend
Iguana ///< A lizard
};
};

// HTML-ANIMAL: <h1>class Animals</h1>
// HTML-ANIMAL: <h2 id="Enums">Enums</h2>
// HTML-ANIMAL: <h3 id="{{([0-9A-F]{40})}}">enum AnimalType</h3>
// HTML-ANIMAL: <li>Dog</li>
// HTML-ANIMAL: <li>Cat</li>
// HTML-ANIMAL: <li>Iguana</li>
// HTML-ANIMAL: <th colspan="3">enum AnimalType</th>
// HTML-ANIMAL: <td>Dog</td>
// HTML-ANIMAL: <td>0</td>
// HTML-ANIMAL: <p> Man&apos;s best friend</p>
// HTML-ANIMAL: <td>Cat</td>
// HTML-ANIMAL: <td>1</td>
// HTML-ANIMAL: <p> Man&apos;s other best friend</p>
// HTML-ANIMAL: <td>Iguana</td>
// HTML-ANIMAL: <td>2</td>
// HTML-ANIMAL: <p> A lizard</p>


// MD-ANIMAL: # class Animals
// MD-ANIMAL: ## Enums
Expand All @@ -106,10 +126,11 @@ namespace Vehicles {
enum Car {
// MD-VEHICLES-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-VEHICLES-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
Sedan, /// Sedan
SUV, /// SUV
Pickup, /// Pickup
Hatchback /// Hatchback

Sedan, ///< Comment 1
SUV, ///< Comment 2
Pickup, ///< Comment 3
Hatchback ///< Comment 4
};
}

Expand All @@ -124,9 +145,37 @@ namespace Vehicles {
// MD-VEHICLES: **brief** specify type of car

// HTML-VEHICLES: <h1>namespace Vehicles</h1>
// HTML-VEHICLES: <h2 id="Enums">Enums</h2>
// HTML-VEHICLES: <h3 id="{{([0-9A-F]{40})}}">enum Car</h3>
// HTML-VEHICLES: <li>Sedan</li>
// HTML-VEHICLES: <li>SUV</li>
// HTML-VEHICLES: <li>Pickup</li>
// HTML-VEHICLES: <li>Hatchback</li>
// HTML-VEHICLES: <th colspan="3">enum Car</th>
// HTML-VEHICLES: <td>Sedan</td>
// HTML-VEHICLES: <td>0</td>
// HTML-VEHICLES: <p> Comment 1</p>
// HTML-VEHICLES: <td>SUV</td>
// HTML-VEHICLES: <td>1</td>
// HTML-VEHICLES: <p> Comment 2</p>
// HTML-VEHICLES: <td>Pickup</td>
// HTML-VEHICLES: <td>2</td>
// HTML-VEHICLES: <p> Comment 3</p>
// HTML-VEHICLES: <td>Hatchback</td>
// HTML-VEHICLES: <td>3</td>
// HTML-VEHICLES: <p> Comment 4</p>


enum ColorUserSpecified {
RedUserSpecified = 'A',
GreenUserSpecified = 2,
BlueUserSpecified = 'C'
};

// MD-INDEX: | enum ColorUserSpecified |
// MD-INDEX: --
// MD-INDEX: | RedUserSpecified |
// MD-INDEX: | GreenUserSpecified |
// MD-INDEX: | BlueUserSpecified |

// HTML-INDEX: <th colspan="2">enum ColorUserSpecified</th>
// HTML-INDEX: <td>RedUserSpecified</td>
// HTML-INDEX: <td>&apos;A&apos;</td>
// HTML-INDEX: <td>GreenUserSpecified</td>
// HTML-INDEX: <td>2</td>
// HTML-INDEX: <td>BlueUserSpecified</td>
// HTML-INDEX: <td>&apos;C&apos;</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %check_clang_tidy %s modernize-use-std-format %t -- \
// RUN: -config="{CheckOptions: \
// RUN: { \
// RUN: modernize-use-std-format.StrFormatLikeFunctions: 'MyClass::StrFormat', \
// RUN: modernize-use-std-format.ReplacementFormatFunction: 'format', \
// RUN: } \
// RUN: }" \
// RUN: -- -isystem %clang_tidy_headers

#include <cstdio>
#include <string.h>
#include <string>

struct MyClass
{
template <typename S, typename... Args>
std::string StrFormat(const S &format, const Args&... args);
};

std::string StrFormat_simple(MyClass &myclass, MyClass *pmyclass) {
std::string s;

s += myclass.StrFormat("MyClass::StrFormat dot %d", 42);
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format]
// CHECK-FIXES: s += myclass.format("MyClass::StrFormat dot {}", 42);

s += pmyclass->StrFormat("MyClass::StrFormat pointer %d", 43);
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format]
// CHECK-FIXES: s += pmyclass->format("MyClass::StrFormat pointer {}", 43);

s += (*pmyclass).StrFormat("MyClass::StrFormat deref pointer %d", 44);
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format]
// CHECK-FIXES: s += (*pmyclass).format("MyClass::StrFormat deref pointer {}", 44);

return s;
}

struct MyDerivedClass : public MyClass {};

std::string StrFormat_derived(MyDerivedClass &derived) {
return derived.StrFormat("MyDerivedClass::StrFormat dot %d", 42);
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'format' instead of 'StrFormat' [modernize-use-std-format]
// CHECK-FIXES: return derived.format("MyDerivedClass::StrFormat dot {}", 42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// RUN: %check_clang_tidy %s modernize-use-std-print %t -- \
// RUN: -config="{CheckOptions: \
// RUN: { \
// RUN: modernize-use-std-print.PrintfLikeFunctions: 'MyClass::printf', \
// RUN: modernize-use-std-print.FprintfLikeFunctions: 'MyClass::fprintf', \
// RUN: modernize-use-std-print.ReplacementPrintFunction: 'print', \
// RUN: modernize-use-std-print.ReplacementPrintlnFunction: 'println', \
// RUN: } \
// RUN: }" \
// RUN: -- -isystem %clang_tidy_headers

#include <cstdio>
#include <string.h>

struct MyStruct {};

struct MyClass
{
template <typename... Args>
void printf(const char *fmt, Args &&...);
template <typename... Args>
int fprintf(MyStruct *param1, const char *fmt, Args &&...);
};

void printf_simple(MyClass &myclass, MyClass *pmyclass) {
myclass.printf("printf dot %d", 42);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: myclass.print("printf dot {}", 42);

pmyclass->printf("printf pointer %d", 43);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: pmyclass->print("printf pointer {}", 43);

(*pmyclass).printf("printf deref pointer %d", 44);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: (*pmyclass).print("printf deref pointer {}", 44);
}

void printf_newline(MyClass &myclass, MyClass *pmyclass) {
myclass.printf("printf dot newline %c\n", 'A');
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'println' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: myclass.println("printf dot newline {}", 'A');

pmyclass->printf("printf pointer newline %c\n", 'B');
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'println' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: pmyclass->println("printf pointer newline {}", 'B');
}

void fprintf_simple(MyStruct *mystruct, MyClass &myclass, MyClass *pmyclass) {
myclass.fprintf(mystruct, "fprintf dot %d", 142);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'fprintf' [modernize-use-std-print]
// CHECK-FIXES: myclass.print(mystruct, "fprintf dot {}", 142);

pmyclass->fprintf(mystruct, "fprintf pointer %d", 143);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'fprintf' [modernize-use-std-print]
// CHECK-FIXES: pmyclass->print(mystruct, "fprintf pointer {}", 143);

(*pmyclass).fprintf(mystruct, "fprintf deref pointer %d", 144);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'fprintf' [modernize-use-std-print]
// CHECK-FIXES: (*pmyclass).print(mystruct, "fprintf deref pointer {}", 144);
}

struct MyDerivedClass : public MyClass {};

void printf_derived(MyDerivedClass &derived)
{
derived.printf("printf on derived class %d", 42);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'print' instead of 'printf' [modernize-use-std-print]
// CHECK-FIXES: derived.print("printf on derived class {}", 42);
}
33 changes: 27 additions & 6 deletions clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ TEST(HTMLGeneratorTest, emitNamespaceHTML) {
</div>
<h2 id="Enums">Enums</h2>
<div>
<h3 id="0000000000000000000000000000000000000000">enum OneEnum</h3>
<table id="0000000000000000000000000000000000000000">
<thead>
<tr>
<th colspan="2">enum OneEnum</th>
</tr>
</thead>
</table>
</div>
</div>
<div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
Expand Down Expand Up @@ -214,7 +220,13 @@ TEST(HTMLGeneratorTest, emitRecordHTML) {
</div>
<h2 id="Enums">Enums</h2>
<div>
<h3 id="0000000000000000000000000000000000000000">enum OneEnum</h3>
<table id="0000000000000000000000000000000000000000">
<thead>
<tr>
<th colspan="2">enum OneEnum</th>
</tr>
</thead>
</table>
</div>
</div>
<div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
Expand Down Expand Up @@ -348,10 +360,19 @@ TEST(HTMLGeneratorTest, emitEnumHTML) {
<main>
<div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
<div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
<h3 id="0000000000000000000000000000000000000000">enum class e</h3>
<ul>
<li>X</li>
</ul>
<table id="0000000000000000000000000000000000000000">
<thead>
<tr>
<th colspan="2">enum class e</th>
</tr>
</thead>
<tbody>
<tr>
<td>X</td>
<td>0</td>
</tr>
</tbody>
</table>
<p>
Defined at line
<a href="https://www.repository.com/test.cpp#10">10</a>
Expand Down
36 changes: 31 additions & 5 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,8 @@ the configuration (without a prefix: ``Auto``).

**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15` :ref:`<IndentRequiresClause>`
Indent the requires clause in a template. This only applies when
``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
or ``WithFollowing``.

In clang-format 12, 13 and 14 it was named ``IndentRequires``.

Expand Down Expand Up @@ -5419,23 +5420,48 @@ the configuration (without a prefix: ``Auto``).
Possible values:

* ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
Always put the ``requires`` clause on its own line.
Always put the ``requires`` clause on its own line (possibly followed by
a semicolon).

.. code-block:: c++

template <typename T>
requires C<T>
requires C<T>
struct Foo {...

template <typename T>
requires C<T>
void bar(T t)
requires C<T>;

template <typename T>
requires C<T>
void bar(T t) {...

template <typename T>
void baz(T t)
requires C<T>
requires C<T>
{...

* ``RCPS_OwnLineWithBrace`` (in configuration: ``OwnLineWithBrace``)
As with ``OwnLine``, except, unless otherwise prohibited, place a
following open brace (of a function definition) to follow on the same
line.

.. code-block:: c++

void bar(T t)
requires C<T> {
return;
}

void bar(T t)
requires C<T> {}

template <typename T>
requires C<T>
void baz(T t) {
...

* ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
Try to put the clause together with the preceding part of a declaration.
For class templates: stick to the template declaration.
Expand Down
2 changes: 1 addition & 1 deletion clang/docs/ClangFormattedStatus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ tree in terms of conformance to :doc:`ClangFormat` as of: March 06, 2022 17:32:2
- `2`
- `79`
- :part:`2%`
* - clang/lib/AST/Interp
* - clang/lib/AST/ByteCode
- `44`
- `18`
- `26`
Expand Down
16 changes: 15 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ C++ Specific Potentially Breaking Changes
template <> // error: extraneous template head
template <typename T>
void f();

ABI Changes in This Version
---------------------------

Expand Down Expand Up @@ -161,6 +161,10 @@ C23 Feature Support
Non-comprehensive list of changes in this release
-------------------------------------------------

- The floating point comparison builtins (``__builtin_isgreater``,
``__builtin_isgreaterequal``, ``__builtin_isless``, etc.) and
``__builtin_signbit`` can now be used in constant expressions.

New Compiler Flags
------------------

Expand All @@ -170,6 +174,8 @@ Deprecated Compiler Flags
Modified Compiler Flags
-----------------------

- The compiler flag `-fbracket-depth` default value is increased from 256 to 2048.

Removed Compiler Flags
-------------------------

Expand All @@ -189,6 +195,9 @@ Attribute Changes in Clang
- The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It can be used to specify
that a function requires an additional x86-64 thunk, which may be patched at runtime.

- ``[[clang::lifetimebound]]`` is now explicitly disallowed on explicit object member functions
where they were previously silently ignored.

Improvements to Clang's diagnostics
-----------------------------------

Expand All @@ -214,6 +223,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid according to [basic.start.main] p3. Fixes #GH101512.

- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391.

Improvements to Clang's time-trace
----------------------------------

Expand Down Expand Up @@ -264,10 +275,13 @@ Bug Fixes to C++ Support
- Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter.
- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990).
- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^

- Fixed a crash that occurred when dividing by zero in complex integer division. (#GH55390).

Miscellaneous Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
36 changes: 18 additions & 18 deletions clang/docs/tools/clang-formatted-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,24 @@ clang/lib/APINotes/APINotesTypes.cpp
clang/lib/APINotes/APINotesYAMLCompiler.cpp
clang/lib/AST/DataCollection.cpp
clang/lib/AST/Linkage.h
clang/lib/AST/Interp/ByteCodeGenError.cpp
clang/lib/AST/Interp/ByteCodeGenError.h
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Frame.cpp
clang/lib/AST/Interp/Frame.h
clang/lib/AST/Interp/InterpState.h
clang/lib/AST/Interp/Opcode.h
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/Record.h
clang/lib/AST/Interp/Source.cpp
clang/lib/AST/Interp/Source.h
clang/lib/AST/Interp/State.cpp
clang/lib/AST/Interp/State.h
clang/lib/AST/ByteCode/ByteCodeGenError.cpp
clang/lib/AST/ByteCode/ByteCodeGenError.h
clang/lib/AST/ByteCode/Context.cpp
clang/lib/AST/ByteCode/Context.h
clang/lib/AST/ByteCode/Descriptor.cpp
clang/lib/AST/ByteCode/Disasm.cpp
clang/lib/AST/ByteCode/EvalEmitter.h
clang/lib/AST/ByteCode/Frame.cpp
clang/lib/AST/ByteCode/Frame.h
clang/lib/AST/ByteCode/InterpState.h
clang/lib/AST/ByteCode/Opcode.h
clang/lib/AST/ByteCode/Pointer.cpp
clang/lib/AST/ByteCode/PrimType.cpp
clang/lib/AST/ByteCode/Record.h
clang/lib/AST/ByteCode/Source.cpp
clang/lib/AST/ByteCode/Source.h
clang/lib/AST/ByteCode/State.cpp
clang/lib/AST/ByteCode/State.h
clang/lib/ASTMatchers/GtestMatchers.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/Basic/Attributes.cpp
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/APINotes/APINotesReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class APINotesReader {
ObjCSelectorRef Selector,
bool IsInstanceMethod);

/// Look for information regarding the given field of a C struct.
///
/// \param Name The name of the field.
///
/// \returns information about the field, if known.
VersionedInfo<FieldInfo> lookupField(ContextID CtxID, llvm::StringRef Name);

/// Look for information regarding the given C++ method in the given C++ tag
/// context.
///
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/APINotes/APINotesWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ class APINotesWriter {
void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);

/// Add information about a specific C record field.
///
/// \param CtxID The context in which this field resides, i.e. a C/C++ tag.
/// \param Name The name of the field.
/// \param Info Information about this field.
void addField(ContextID CtxID, llvm::StringRef Name, const FieldInfo &Info,
llvm::VersionTuple SwiftVersion);

/// Add information about a global variable.
///
/// \param Name The name of this global variable.
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/APINotes/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ class GlobalFunctionInfo : public FunctionInfo {
GlobalFunctionInfo() {}
};

/// Describes API notes data for a C/C++ record field.
class FieldInfo : public VariableInfo {
public:
FieldInfo() {}
};

/// Describes API notes data for a C++ method.
class CXXMethodInfo : public FunctionInfo {
public:
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class ParamIdx {
static_assert(sizeof(ParamIdx) == sizeof(ParamIdx::SerialType),
"ParamIdx does not fit its serialization type");

#include "clang/AST/Attrs.inc"
#include "clang/AST/Attrs.inc" // IWYU pragma: export

inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
const Attr *At) {
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Analysis/FlowSensitive/ASTOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ struct ReferencedDecls {
/// All variables with static storage duration, notably including static
/// member variables and static variables declared within a function.
llvm::DenseSet<const VarDecl *> Globals;
/// Local variables, not including parameters or static variables declared
/// within a function.
llvm::DenseSet<const VarDecl *> Locals;
/// Free functions and member functions which are referenced (but not
/// necessarily called).
llvm::DenseSet<const FunctionDecl *> Functions;
Expand Down
20 changes: 11 additions & 9 deletions clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -533,42 +533,42 @@ def BuiltinComplex : Builtin {
def IsGreater : Builtin {
let Spellings = ["__builtin_isgreater"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def IsGreaterEqual : Builtin {
let Spellings = ["__builtin_isgreaterequal"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def IsLess : Builtin {
let Spellings = ["__builtin_isless"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def IsLessEqual : Builtin {
let Spellings = ["__builtin_islessequal"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def IsLessGreater : Builtin {
let Spellings = ["__builtin_islessgreater"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def IsUnordered : Builtin {
let Spellings = ["__builtin_isunordered"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

Expand Down Expand Up @@ -646,19 +646,21 @@ def IsFPClass : Builtin {
def Signbit : Builtin {
let Spellings = ["__builtin_signbit"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
CustomTypeChecking];
CustomTypeChecking, Constexpr];
let Prototype = "int(...)";
}

def SignbitF : Builtin {
let Spellings = ["__builtin_signbitf"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
Constexpr];
let Prototype = "int(float)";
}

def SignbitL : Builtin {
let Spellings = ["__builtin_signbitl"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
Constexpr];
let Prototype = "int(long double)";
}

Expand Down
15 changes: 15 additions & 0 deletions clang/include/clang/Basic/BuiltinsNVPTX.def
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ TARGET_BUILTIN(__nvvm_f2bf16_rz_relu, "yf", "", AND(SM_80,PTX70))

TARGET_BUILTIN(__nvvm_f2tf32_rna, "ZUif", "", AND(SM_80,PTX70))

TARGET_BUILTIN(__nvvm_ff_to_e4m3x2_rn, "sff", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_ff_to_e4m3x2_rn_relu, "sff", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_ff_to_e5m2x2_rn, "sff", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_ff_to_e5m2x2_rn_relu, "sff", "", AND(SM_89,PTX81))

TARGET_BUILTIN(__nvvm_f16x2_to_e4m3x2_rn, "sV2h", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_f16x2_to_e4m3x2_rn_relu, "sV2h", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_f16x2_to_e5m2x2_rn, "sV2h", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_f16x2_to_e5m2x2_rn_relu, "sV2h", "", AND(SM_89,PTX81))

TARGET_BUILTIN(__nvvm_e4m3x2_to_f16x2_rn, "V2hs", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_e4m3x2_to_f16x2_rn_relu, "V2hs", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_e5m2x2_to_f16x2_rn, "V2hs", "", AND(SM_89,PTX81))
TARGET_BUILTIN(__nvvm_e5m2x2_to_f16x2_rn_relu, "V2hs", "", AND(SM_89,PTX81))

// Bitcast

BUILTIN(__nvvm_bitcast_f2i, "if", "")
Expand Down
9 changes: 7 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -5667,6 +5667,8 @@ def err_explicit_instantiation_internal_linkage : Error<
def err_explicit_instantiation_not_known : Error<
"explicit instantiation of %0 does not refer to a function template, "
"variable template, member function, member class, or static data member">;
def err_explicit_instantiation_no_candidate : Error<
"no viable candidate for explicit instantiation of %0">;
def note_explicit_instantiation_here : Note<
"explicit instantiation refers here">;
def err_explicit_instantiation_data_member_not_instantiated : Error<
Expand Down Expand Up @@ -10066,8 +10068,9 @@ def warn_null_ret : Warning<
InGroup<NonNull>;

def err_lifetimebound_no_object_param : Error<
"'lifetimebound' attribute cannot be applied; %select{static |non-}0member "
"function has no implicit object parameter">;
"'lifetimebound' attribute cannot be applied; "
"%select{non-|static |explicit object }0"
"member function has no implicit object parameter">;
def err_lifetimebound_ctor_dtor : Error<
"'lifetimebound' attribute cannot be applied to a "
"%select{constructor|destructor}0">;
Expand Down Expand Up @@ -11164,6 +11167,8 @@ def err_omp_loop_diff_cxx : Error<
"upper and lower loop bounds">;
def err_omp_loop_cannot_use_stmt : Error<
"'%0' statement cannot be used in OpenMP for loop">;
def err_omp_loop_bad_collapse_var : Error<
"cannot use variable %1 in collapsed imperfectly-nested loop %select{init|condition|increment}0 statement">;
def err_omp_simd_region_cannot_use_stmt : Error<
"'%0' statement cannot be used in OpenMP simd region">;
def warn_omp_loop_64_bit_var : Warning<
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -7959,7 +7959,7 @@ def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-
MarshallingInfoFlag<LangOpts<"SetVisibilityForExternDecls">>;
def fbracket_depth : Separate<["-"], "fbracket-depth">,
HelpText<"Maximum nesting level for parentheses, brackets, and braces">,
MarshallingInfoInt<LangOpts<"BracketDepth">, "256">;
MarshallingInfoInt<LangOpts<"BracketDepth">, "2048">;
defm const_strings : BoolOption<"f", "const-strings",
LangOpts<"ConstStrings">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use">,
Expand Down
34 changes: 29 additions & 5 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,8 @@ struct FormatStyle {
PPDirectiveIndentStyle IndentPPDirectives;

/// Indent the requires clause in a template. This only applies when
/// ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
/// ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
/// or ``WithFollowing``.
///
/// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
/// \code
Expand Down Expand Up @@ -3944,22 +3945,45 @@ struct FormatStyle {
/// ``IndentRequires`` option is only used if the ``requires`` is put on the
/// start of a line.
enum RequiresClausePositionStyle : int8_t {
/// Always put the ``requires`` clause on its own line.
/// Always put the ``requires`` clause on its own line (possibly followed by
/// a semicolon).
/// \code
/// template <typename T>
/// requires C<T>
/// requires C<T>
/// struct Foo {...
///
/// template <typename T>
/// requires C<T>
/// void bar(T t)
/// requires C<T>;
///
/// template <typename T>
/// requires C<T>
/// void bar(T t) {...
///
/// template <typename T>
/// void baz(T t)
/// requires C<T>
/// requires C<T>
/// {...
/// \endcode
RCPS_OwnLine,
/// As with ``OwnLine``, except, unless otherwise prohibited, place a
/// following open brace (of a function definition) to follow on the same
/// line.
/// \code
/// void bar(T t)
/// requires C<T> {
/// return;
/// }
///
/// void bar(T t)
/// requires C<T> {}
///
/// template <typename T>
/// requires C<T>
/// void baz(T t) {
/// ...
/// \endcode
RCPS_OwnLineWithBrace,
/// Try to put the clause together with the preceding part of a declaration.
/// For class templates: stick to the template declaration.
/// For function templates: stick to the template declaration.
Expand Down
50 changes: 0 additions & 50 deletions clang/include/clang/Rewrite/Core/DeltaTree.h

This file was deleted.

11 changes: 7 additions & 4 deletions clang/include/clang/Rewrite/Core/HTMLRewrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#include "clang/Basic/SourceLocation.h"
#include <string>

namespace llvm {
class RewriteBuffer;
} // namespace llvm

namespace clang {

class Rewriter;
class RewriteBuffer;
class Preprocessor;

namespace html {
Expand Down Expand Up @@ -53,9 +56,9 @@ namespace html {

/// HighlightRange - This is the same as the above method, but takes
/// decomposed file locations.
void HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
const char *BufferStart,
const char *StartTag, const char *EndTag);
void HighlightRange(llvm::RewriteBuffer &RB, unsigned B, unsigned E,
const char *BufferStart, const char *StartTag,
const char *EndTag);

/// EscapeText - HTMLize a specified file so that special characters are
/// are translated so that they are not interpreted as HTML tags.
Expand Down
223 changes: 0 additions & 223 deletions clang/include/clang/Rewrite/Core/RewriteRope.h

This file was deleted.

19 changes: 10 additions & 9 deletions clang/include/clang/Rewrite/Core/Rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Rewrite/Core/RewriteBuffer.h"
#include "llvm/ADT/RewriteBuffer.h"
#include "llvm/ADT/StringRef.h"
#include <map>
#include <string>
Expand All @@ -32,7 +32,7 @@ class SourceManager;
class Rewriter {
SourceManager *SourceMgr = nullptr;
const LangOptions *LangOpts = nullptr;
std::map<FileID, RewriteBuffer> RewriteBuffers;
std::map<FileID, llvm::RewriteBuffer> RewriteBuffers;

public:
struct RewriteOptions {
Expand All @@ -49,7 +49,7 @@ class Rewriter {
///
/// FIXME: This sometimes corrupts the file's rewrite buffer due to
/// incorrect indexing in the implementation (see the FIXME in
/// clang::RewriteBuffer::RemoveText). Moreover, it's inefficient because
/// llvm::RewriteBuffer::RemoveText). Moreover, it's inefficient because
/// it must scan the buffer from the beginning to find the start of the
/// line. When feasible, it's better for the caller to check for a blank
/// line and then, if found, expand the removal range to include it.
Expand All @@ -62,8 +62,9 @@ class Rewriter {
RewriteOptions() {}
};

using buffer_iterator = std::map<FileID, RewriteBuffer>::iterator;
using const_buffer_iterator = std::map<FileID, RewriteBuffer>::const_iterator;
using buffer_iterator = std::map<FileID, llvm::RewriteBuffer>::iterator;
using const_buffer_iterator =
std::map<FileID, llvm::RewriteBuffer>::const_iterator;

explicit Rewriter() = default;
explicit Rewriter(SourceManager &SM, const LangOptions &LO)
Expand Down Expand Up @@ -191,13 +192,13 @@ class Rewriter {
/// buffer, and allows you to write on it directly. This is useful if you
/// want efficient low-level access to apis for scribbling on one specific
/// FileID's buffer.
RewriteBuffer &getEditBuffer(FileID FID);
llvm::RewriteBuffer &getEditBuffer(FileID FID);

/// getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
/// If no modification has been made to it, return null.
const RewriteBuffer *getRewriteBufferFor(FileID FID) const {
std::map<FileID, RewriteBuffer>::const_iterator I =
RewriteBuffers.find(FID);
const llvm::RewriteBuffer *getRewriteBufferFor(FileID FID) const {
std::map<FileID, llvm::RewriteBuffer>::const_iterator I =
RewriteBuffers.find(FID);
return I == RewriteBuffers.end() ? nullptr : &I->second;
}

Expand Down
156 changes: 57 additions & 99 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,161 +15,143 @@
#define LLVM_CLANG_SEMA_SEMA_H

#include "clang/APINotes/APINotesManager.h"
#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Availability.h"
#include "clang/AST/ComparisonCategories.h"
#include "clang/AST/AttrIterator.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprConcepts.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/LocInfoType.h"
#include "clang/AST/MangleNumberingContext.h"
#include "clang/AST/NSAPI.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeOrdering.h"
#include "clang/Basic/BitmaskEnum.h"
#include "clang/Basic/AttrSubjectMatchRules.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CapturedStmt.h"
#include "clang/Basic/Cuda.h"
#include "clang/Basic/DarwinSDKInfo.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/ExpressionTraits.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Lambda.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/OpenCLOptions.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/PragmaKinds.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/TypeTraits.h"
#include "clang/Sema/AnalysisBasedWarnings.h"
#include "clang/Sema/Attr.h"
#include "clang/Sema/CleanupInfo.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/Sema/IdentifierResolver.h"
#include "clang/Sema/ObjCMethodList.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/Redeclaration.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"
#include "clang/Sema/SemaConcept.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/Sema/TypoCorrection.h"
#include "clang/Sema/Weak.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FloatingPointMode.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <functional>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

namespace llvm {
class APSInt;
template <typename ValueT, typename ValueInfoT> class DenseSet;
class SmallBitVector;
struct InlineAsmIdentifierInfo;
} // namespace llvm

namespace clang {
class ADLResult;
class APValue;
struct ASTConstraintSatisfaction;
class ASTConsumer;
class ASTContext;
class ASTDeclReader;
class ASTMutationListener;
class ASTReader;
class ASTWriter;
class ArrayType;
class ParsedAttr;
class BindingDecl;
class BlockDecl;
class CapturedDecl;
class CXXBasePath;
class CXXBasePaths;
class CXXBindTemporaryExpr;
typedef SmallVector<CXXBaseSpecifier *, 4> CXXCastPath;
class CXXConstructorDecl;
class CXXConversionDecl;
class CXXDeleteExpr;
class CXXDestructorDecl;
class CXXFieldCollector;
class CXXMemberCallExpr;
class CXXMethodDecl;
class CXXScopeSpec;
class CXXTemporary;
class CXXTryStmt;
class CallExpr;
class ClassTemplateDecl;
class ClassTemplatePartialSpecializationDecl;
class ClassTemplateSpecializationDecl;
class VarTemplatePartialSpecializationDecl;
class CodeCompleteConsumer;
class CodeCompletionAllocator;
class CodeCompletionTUInfo;
class CodeCompletionResult;
class CoroutineBodyStmt;
class Decl;
class DeclAccessPair;
class DeclContext;
class DeclRefExpr;
class DeclaratorDecl;
enum class ComparisonCategoryType : unsigned char;
class ConstraintSatisfaction;
class DarwinSDKInfo;
class DeclGroupRef;
class DeducedTemplateArgument;
struct DeductionFailureInfo;
class DependentDiagnostic;
class DesignatedInitExpr;
class Designation;
class EnableIfAttr;
class EnumConstantDecl;
class Expr;
class ExtVectorType;
class FormatAttr;
class FriendDecl;
class FunctionDecl;
class FunctionProtoType;
class FunctionTemplateDecl;
class IdentifierInfo;
class ImplicitConversionSequence;
typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList;
class InitListExpr;
class InitializationKind;
class InitializationSequence;
class InitializedEntity;
class IntegerLiteral;
class LabelStmt;
class LambdaExpr;
class LangOptions;
enum class LangAS : unsigned int;
class LocalInstantiationScope;
class LookupResult;
class MacroInfo;
class MangleNumberingContext;
typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
class ModuleLoader;
class MultiLevelTemplateArgumentList;
class NamedDecl;
class ObjCImplementationDecl;
struct NormalizedConstraint;
class ObjCInterfaceDecl;
class ObjCMethodDecl;
class ObjCProtocolDecl;
struct OverloadCandidate;
enum class OverloadCandidateParamOrder : char;
enum OverloadCandidateRewriteKind : unsigned;
class OverloadCandidateSet;
class OverloadExpr;
class ParenListExpr;
class ParmVarDecl;
class Preprocessor;
class PseudoDestructorTypeStorage;
class PseudoObjectExpr;
class QualType;
class SemaAMDGPU;
class SemaARM;
class SemaAVR;
Expand All @@ -196,41 +178,19 @@ class SemaSystemZ;
class SemaWasm;
class SemaX86;
class StandardConversionSequence;
class Stmt;
class StringLiteral;
class SwitchStmt;
class TemplateArgument;
class TemplateArgumentList;
class TemplateArgumentLoc;
class TemplateDecl;
class TemplateInstantiationCallback;
class TemplateParameterList;
class TemplatePartialOrderingContext;
class TemplateTemplateParmDecl;
class TemplateSpecCandidateSet;
class Token;
class TypeAliasDecl;
class TypedefDecl;
class TypedefNameDecl;
class TypeLoc;
class TypeConstraint;
class TypoCorrectionConsumer;
class UnqualifiedId;
class UnresolvedLookupExpr;
class UnresolvedMemberExpr;
class UnresolvedSetImpl;
class UnresolvedSetIterator;
class UsingDecl;
class UsingShadowDecl;
class ValueDecl;
class VarDecl;
class VarTemplateSpecializationDecl;
class VisibilityAttr;
class VisibleDeclConsumer;
class IndirectFieldDecl;
struct DeductionFailureInfo;
class TemplateSpecCandidateSet;

namespace sema {
class AccessedEntity;
class BlockScopeInfo;
class Capture;
class CapturedRegionScopeInfo;
Expand All @@ -240,8 +200,6 @@ class DelayedDiagnostic;
class DelayedDiagnosticPool;
class FunctionScopeInfo;
class LambdaScopeInfo;
class PossiblyUnreachableDiag;
class RISCVIntrinsicManager;
class SemaPPCallbacks;
class TemplateDeductionInfo;
} // namespace sema
Expand Down
9 changes: 4 additions & 5 deletions clang/include/clang/Sema/SemaAMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#ifndef LLVM_CLANG_SEMA_SEMAAMDGPU_H
#define LLVM_CLANG_SEMA_SEMAAMDGPU_H

#include "clang/AST/Attr.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class AttributeCommonInfo;
class ParsedAttr;

class SemaAMDGPU : public SemaBase {
public:
SemaAMDGPU(Sema &S);
Expand Down
19 changes: 11 additions & 8 deletions clang/include/clang/Sema/SemaARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
#ifndef LLVM_CLANG_SEMA_SEMAARM_H
#define LLVM_CLANG_SEMA_SEMAARM_H

#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <tuple>

namespace llvm {
template <typename T, unsigned N> class SmallVector;
} // namespace llvm

namespace clang {
class ParsedAttr;
class TargetInfo;

class SemaARM : public SemaBase {
public:
Expand Down Expand Up @@ -60,10 +63,10 @@ class SemaARM : public SemaBase {
unsigned ExpectedFieldNum, bool AllowName);
bool BuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall);

bool MveAliasValid(unsigned BuiltinID, StringRef AliasName);
bool CdeAliasValid(unsigned BuiltinID, StringRef AliasName);
bool SveAliasValid(unsigned BuiltinID, StringRef AliasName);
bool SmeAliasValid(unsigned BuiltinID, StringRef AliasName);
bool MveAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
bool CdeAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
bool SveAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
bool SmeAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
void handleBuiltinAliasAttr(Decl *D, const ParsedAttr &AL);
void handleNewAttr(Decl *D, const ParsedAttr &AL);
void handleCmseNSEntryAttr(Decl *D, const ParsedAttr &AL);
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaAVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#ifndef LLVM_CLANG_SEMA_SEMAAVR_H
#define LLVM_CLANG_SEMA_SEMAAVR_H

#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class Decl;
class ParsedAttr;

class SemaAVR : public SemaBase {
Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/Sema/SemaBPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#ifndef LLVM_CLANG_SEMA_SEMABPF_H
#define LLVM_CLANG_SEMA_SEMABPF_H

#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
Expand Down
20 changes: 15 additions & 5 deletions clang/include/clang/Sema/SemaCUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@
#ifndef LLVM_CLANG_SEMA_SEMACUDA_H
#define LLVM_CLANG_SEMA_SEMACUDA_H

#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/DeclAccessPair.h"
#include "clang/AST/Redeclarable.h"
#include "clang/Basic/Cuda.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include <string>
#include <utility>

namespace clang {
namespace sema {
class Capture;
} // namespace sema

class ASTReader;
class ASTWriter;
enum class CUDAFunctionTarget;
enum class CXXSpecialMemberKind;
class ParsedAttributesView;
class Scope;

class SemaCUDA : public SemaBase {
public:
Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/Sema/SemaCodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
#ifndef LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
#define LLVM_CLANG_SEMA_SEMACODECOMPLETION_H

#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Designator.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/StringRef.h"
#include <optional>

namespace clang {
class DeclGroupRef;
class MacroInfo;
class Scope;
class TemplateName;

class SemaCodeCompletion : public SemaBase {
public:
Expand Down
11 changes: 5 additions & 6 deletions clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
#ifndef LLVM_CLANG_SEMA_SEMAHLSL_H
#define LLVM_CLANG_SEMA_SEMAHLSL_H

#include "clang/AST/ASTFwd.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/TargetParser/Triple.h"
#include <initializer_list>

namespace clang {
class AttributeCommonInfo;
class IdentifierInfo;
class ParsedAttr;
class Scope;

class SemaHLSL : public SemaBase {
public:
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaHexagon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef LLVM_CLANG_SEMA_SEMAHEXAGON_H
#define LLVM_CLANG_SEMA_SEMAHEXAGON_H

#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Sema/SemaLoongArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#ifndef LLVM_CLANG_SEMA_SEMALOONGARCH_H
#define LLVM_CLANG_SEMA_SEMALOONGARCH_H

#include "clang/AST/Expr.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class TargetInfo;

class SemaLoongArch : public SemaBase {
public:
SemaLoongArch(Sema &S);
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaM68k.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#ifndef LLVM_CLANG_SEMA_SEMAM68K_H
#define LLVM_CLANG_SEMA_SEMAM68K_H

#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class Decl;
class ParsedAttr;

class SemaM68k : public SemaBase {
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Sema/SemaMIPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
#ifndef LLVM_CLANG_SEMA_SEMAMIPS_H
#define LLVM_CLANG_SEMA_SEMAMIPS_H

#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class ParsedAttr;
class TargetInfo;

class SemaMIPS : public SemaBase {
public:
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaMSP430.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#ifndef LLVM_CLANG_SEMA_SEMAMSP430_H
#define LLVM_CLANG_SEMA_SEMAMSP430_H

#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class Decl;
class ParsedAttr;

class SemaMSP430 : public SemaBase {
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Sema/SemaNVPTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#ifndef LLVM_CLANG_SEMA_SEMANVPTX_H
#define LLVM_CLANG_SEMA_SEMANVPTX_H

#include "clang/AST/Expr.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class TargetInfo;

class SemaNVPTX : public SemaBase {
public:
SemaNVPTX(Sema &S);
Expand Down
16 changes: 9 additions & 7 deletions clang/include/clang/Sema/SemaObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
#ifndef LLVM_CLANG_SEMA_SEMAOBJC_H
#define LLVM_CLANG_SEMA_SEMAOBJC_H

#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NSAPI.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/Type.h"
Expand All @@ -27,24 +24,29 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ObjCMethodList.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Redeclaration.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>

namespace clang {

class AttributeCommonInfo;
class AvailabilitySpec;
enum class CheckedConversionKind;
class DeclGroupRef;
class LookupResult;
struct ObjCDictionaryElement;
class ParsedAttr;
class ParsedAttributesView;
class Scope;
struct SkipBodyInfo;

class SemaObjC : public SemaBase {
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Sema/SemaOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@

#include "clang/AST/DeclGroup.h"
#include "clang/AST/StmtOpenACC.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OpenACCKinds.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/SmallVector.h"
#include <cassert>
#include <optional>
#include <utility>
#include <variant>

namespace clang {
class IdentifierInfo;
class OpenACCClause;

class SemaOpenACC : public SemaBase {
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaOpenCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#ifndef LLVM_CLANG_SEMA_SEMAOPENCL_H
#define LLVM_CLANG_SEMA_SEMAOPENCL_H

#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class Decl;
class ParsedAttr;

class SemaOpenCL : public SemaBase {
Expand Down
19 changes: 10 additions & 9 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,36 @@
#ifndef LLVM_CLANG_SEMA_SEMAOPENMP_H
#define LLVM_CLANG_SEMA_SEMAOPENMP_H

#include "clang/AST/ASTFwd.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprOpenMP.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtOpenMP.h"
#include "clang/AST/Type.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Frontend/OpenMP/OMP.h.inc"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include <optional>
#include <string>
#include <utility>

namespace clang {
namespace sema {
class FunctionScopeInfo;
} // namespace sema

class DeclContext;
class DeclGroupRef;
class ParsedAttr;
class Scope;

class SemaOpenMP : public SemaBase {
public:
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Sema/SemaPPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
#ifndef LLVM_CLANG_SEMA_SEMAPPC_H
#define LLVM_CLANG_SEMA_SEMAPPC_H

#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class TargetInfo;

class SemaPPC : public SemaBase {
public:
SemaPPC(Sema &S);
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Sema/SemaPseudoObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#ifndef LLVM_CLANG_SEMA_SEMAPSEUDOOBJECT_H
#define LLVM_CLANG_SEMA_SEMAPSEUDOOBJECT_H

#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/OperationKinds.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class Scope;

class SemaPseudoObject : public SemaBase {
public:
Expand Down
13 changes: 8 additions & 5 deletions clang/include/clang/Sema/SemaRISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
#ifndef LLVM_CLANG_SEMA_SEMARISCV_H
#define LLVM_CLANG_SEMA_SEMARISCV_H

#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/RISCVIntrinsicManager.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include <memory>

namespace clang {
namespace sema {
class RISCVIntrinsicManager;
} // namespace sema

class ParsedAttr;
class TargetInfo;

class SemaRISCV : public SemaBase {
public:
Expand All @@ -39,7 +42,7 @@ class SemaRISCV : public SemaBase {
bool isValidRVVBitcast(QualType srcType, QualType destType);

void handleInterruptAttr(Decl *D, const ParsedAttr &AL);
bool isAliasValid(unsigned BuiltinID, StringRef AliasName);
bool isAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);

/// Indicate RISC-V vector builtin functions enabled or not.
bool DeclareRVVBuiltins = false;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef LLVM_CLANG_SEMA_SEMASYCL_H
#define LLVM_CLANG_SEMA_SEMASYCL_H

#include "clang/AST/Decl.h"
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Ownership.h"
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Sema/SemaSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#ifndef LLVM_CLANG_SEMA_SEMASWIFT_H
#define LLVM_CLANG_SEMA_SEMASWIFT_H

#include "clang/AST/Attr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/StringRef.h"

namespace clang {
class AttributeCommonInfo;
class Decl;
enum class ParameterABI;
class ParsedAttr;
class SwiftNameAttr;

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaSystemZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef LLVM_CLANG_SEMA_SEMASYSTEMZ_H
#define LLVM_CLANG_SEMA_SEMASYSTEMZ_H

#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
Expand Down
9 changes: 4 additions & 5 deletions clang/include/clang/Sema/SemaWasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#ifndef LLVM_CLANG_SEMA_SEMAWASM_H
#define LLVM_CLANG_SEMA_SEMAWASM_H

#include "clang/AST/Attr.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class ParsedAttr;
class TargetInfo;

class SemaWasm : public SemaBase {
public:
SemaWasm(Sema &S);
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Sema/SemaX86.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#ifndef LLVM_CLANG_SEMA_SEMAX86_H
#define LLVM_CLANG_SEMA_SEMAX86_H

#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ASTFwd.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/SemaBase.h"

namespace clang {
class ParsedAttr;
class TargetInfo;

class SemaX86 : public SemaBase {
public:
Expand Down
20 changes: 19 additions & 1 deletion clang/lib/APINotes/APINotesFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const uint16_t VERSION_MAJOR = 0;
/// API notes file minor version number.
///
/// When the format changes IN ANY WAY, this number should be incremented.
const uint16_t VERSION_MINOR = 29; // SwiftConformsTo
const uint16_t VERSION_MINOR = 30; // fields

const uint8_t kSwiftCopyable = 1;
const uint8_t kSwiftNonCopyable = 2;
Expand Down Expand Up @@ -72,6 +72,10 @@ enum BlockID {
/// used in other tables.
OBJC_SELECTOR_BLOCK_ID,

/// The fields data block, which maps names fields of C records to
/// information about the field.
FIELD_BLOCK_ID,

/// The global variables data block, which maps global variable names to
/// information about the global variable.
GLOBAL_VARIABLE_BLOCK_ID,
Expand Down Expand Up @@ -199,6 +203,20 @@ using CXXMethodDataLayout =
>;
} // namespace cxx_method_block

namespace field_block {
enum {
FIELD_DATA = 1,
};

using FieldDataLayout =
llvm::BCRecordLayout<FIELD_DATA, // record ID
llvm::BCVBR<16>, // table offset within the blob (see
// below)
llvm::BCBlob // map from C (context id, name)
// tuples to C field information
>;
} // namespace field_block

namespace objc_selector_block {
enum {
OBJC_SELECTOR_DATA = 1,
Expand Down
130 changes: 130 additions & 0 deletions clang/lib/APINotes/APINotesReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ class ObjCPropertyTableInfo
}
};

/// Used to deserialize the on-disk C record field table.
class FieldTableInfo
: public VersionedTableInfo<FieldTableInfo, SingleDeclTableKey, FieldInfo> {
public:
static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
auto CtxID = endian::readNext<uint32_t, llvm::endianness::little>(Data);
auto NameID = endian::readNext<uint32_t, llvm::endianness::little>(Data);
return {CtxID, NameID};
}

hash_value_type ComputeHash(internal_key_type Key) {
return static_cast<size_t>(Key.hashValue());
}

static FieldInfo readUnversioned(internal_key_type Key,
const uint8_t *&Data) {
FieldInfo Info;
ReadVariableInfo(Data, Info);
return Info;
}
};

/// Read serialized ParamInfo.
void ReadParamInfo(const uint8_t *&Data, ParamInfo &Info) {
ReadVariableInfo(Data, Info);
Expand Down Expand Up @@ -653,6 +675,12 @@ class APINotesReader::Implementation {
/// The Objective-C property table.
std::unique_ptr<SerializedObjCPropertyTable> ObjCPropertyTable;

using SerializedFieldTable =
llvm::OnDiskIterableChainedHashTable<FieldTableInfo>;

/// The C record field table.
std::unique_ptr<SerializedFieldTable> FieldTable;

using SerializedObjCMethodTable =
llvm::OnDiskIterableChainedHashTable<ObjCMethodTableInfo>;

Expand Down Expand Up @@ -720,6 +748,8 @@ class APINotesReader::Implementation {
llvm::SmallVectorImpl<uint64_t> &Scratch);
bool readCXXMethodBlock(llvm::BitstreamCursor &Cursor,
llvm::SmallVectorImpl<uint64_t> &Scratch);
bool readFieldBlock(llvm::BitstreamCursor &Cursor,
llvm::SmallVectorImpl<uint64_t> &Scratch);
bool readObjCSelectorBlock(llvm::BitstreamCursor &Cursor,
llvm::SmallVectorImpl<uint64_t> &Scratch);
bool readGlobalVariableBlock(llvm::BitstreamCursor &Cursor,
Expand Down Expand Up @@ -1252,6 +1282,81 @@ bool APINotesReader::Implementation::readCXXMethodBlock(
return false;
}

bool APINotesReader::Implementation::readFieldBlock(
llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch) {
if (Cursor.EnterSubBlock(FIELD_BLOCK_ID))
return true;

llvm::Expected<llvm::BitstreamEntry> MaybeNext = Cursor.advance();
if (!MaybeNext) {
// FIXME this drops the error on the floor.
consumeError(MaybeNext.takeError());
return false;
}
llvm::BitstreamEntry Next = MaybeNext.get();
while (Next.Kind != llvm::BitstreamEntry::EndBlock) {
if (Next.Kind == llvm::BitstreamEntry::Error)
return true;

if (Next.Kind == llvm::BitstreamEntry::SubBlock) {
// Unknown sub-block, possibly for use by a future version of the
// API notes format.
if (Cursor.SkipBlock())
return true;

MaybeNext = Cursor.advance();
if (!MaybeNext) {
// FIXME this drops the error on the floor.
consumeError(MaybeNext.takeError());
return false;
}
Next = MaybeNext.get();
continue;
}

Scratch.clear();
llvm::StringRef BlobData;
llvm::Expected<unsigned> MaybeKind =
Cursor.readRecord(Next.ID, Scratch, &BlobData);
if (!MaybeKind) {
// FIXME this drops the error on the floor.
consumeError(MaybeKind.takeError());
return false;
}
unsigned Kind = MaybeKind.get();
switch (Kind) {
case field_block::FIELD_DATA: {
// Already saw field table.
if (FieldTable)
return true;

uint32_t tableOffset;
field_block::FieldDataLayout::readRecord(Scratch, tableOffset);
auto base = reinterpret_cast<const uint8_t *>(BlobData.data());

FieldTable.reset(SerializedFieldTable::Create(
base + tableOffset, base + sizeof(uint32_t), base));
break;
}

default:
// Unknown record, possibly for use by a future version of the
// module format.
break;
}

MaybeNext = Cursor.advance();
if (!MaybeNext) {
// FIXME this drops the error on the floor.
consumeError(MaybeNext.takeError());
return false;
}
Next = MaybeNext.get();
}

return false;
}

bool APINotesReader::Implementation::readObjCSelectorBlock(
llvm::BitstreamCursor &Cursor, llvm::SmallVectorImpl<uint64_t> &Scratch) {
if (Cursor.EnterSubBlock(OBJC_SELECTOR_BLOCK_ID))
Expand Down Expand Up @@ -1812,6 +1917,14 @@ APINotesReader::APINotesReader(llvm::MemoryBuffer *InputBuffer,
}
break;

case FIELD_BLOCK_ID:
if (!HasValidControlBlock ||
Implementation->readFieldBlock(Cursor, Scratch)) {
Failed = true;
return;
}
break;

case OBJC_SELECTOR_BLOCK_ID:
if (!HasValidControlBlock ||
Implementation->readObjCSelectorBlock(Cursor, Scratch)) {
Expand Down Expand Up @@ -2031,6 +2144,23 @@ auto APINotesReader::lookupObjCMethod(ContextID CtxID, ObjCSelectorRef Selector,
return {Implementation->SwiftVersion, *Known};
}

auto APINotesReader::lookupField(ContextID CtxID, llvm::StringRef Name)
-> VersionedInfo<FieldInfo> {
if (!Implementation->FieldTable)
return std::nullopt;

std::optional<IdentifierID> NameID = Implementation->getIdentifier(Name);
if (!NameID)
return std::nullopt;

auto Known = Implementation->FieldTable->find(
SingleDeclTableKey(CtxID.Value, *NameID));
if (Known == Implementation->FieldTable->end())
return std::nullopt;

return {Implementation->SwiftVersion, *Known};
}

auto APINotesReader::lookupCXXMethod(ContextID CtxID, llvm::StringRef Name)
-> VersionedInfo<CXXMethodInfo> {
if (!Implementation->CXXMethodTable)
Expand Down
73 changes: 73 additions & 0 deletions clang/lib/APINotes/APINotesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class APINotesWriter::Implementation {
llvm::SmallVector<std::pair<VersionTuple, ObjCPropertyInfo>, 1>>
ObjCProperties;

/// Information about C record fields.
///
/// Indexed by the context ID and name ID.
llvm::DenseMap<SingleDeclTableKey,
llvm::SmallVector<std::pair<VersionTuple, FieldInfo>, 1>>
Fields;

/// Information about Objective-C methods.
///
/// Indexed by the context ID, selector ID, and Boolean (stored as a char)
Expand Down Expand Up @@ -158,6 +165,7 @@ class APINotesWriter::Implementation {
void writeObjCPropertyBlock(llvm::BitstreamWriter &Stream);
void writeObjCMethodBlock(llvm::BitstreamWriter &Stream);
void writeCXXMethodBlock(llvm::BitstreamWriter &Stream);
void writeFieldBlock(llvm::BitstreamWriter &Stream);
void writeObjCSelectorBlock(llvm::BitstreamWriter &Stream);
void writeGlobalVariableBlock(llvm::BitstreamWriter &Stream);
void writeGlobalFunctionBlock(llvm::BitstreamWriter &Stream);
Expand Down Expand Up @@ -190,6 +198,7 @@ void APINotesWriter::Implementation::writeToStream(llvm::raw_ostream &OS) {
writeObjCPropertyBlock(Stream);
writeObjCMethodBlock(Stream);
writeCXXMethodBlock(Stream);
writeFieldBlock(Stream);
writeObjCSelectorBlock(Stream);
writeGlobalVariableBlock(Stream);
writeGlobalFunctionBlock(Stream);
Expand Down Expand Up @@ -858,6 +867,62 @@ void APINotesWriter::Implementation::writeCXXMethodBlock(
}
}

namespace {
/// Used to serialize the on-disk C field table.
class FieldTableInfo
: public VersionedTableInfo<FieldTableInfo, SingleDeclTableKey, FieldInfo> {
public:
unsigned getKeyLength(key_type_ref) {
return sizeof(uint32_t) + sizeof(uint32_t);
}

void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) {
llvm::support::endian::Writer writer(OS, llvm::endianness::little);
writer.write<uint32_t>(Key.parentContextID);
writer.write<uint32_t>(Key.nameID);
}

hash_value_type ComputeHash(key_type_ref key) {
return static_cast<size_t>(key.hashValue());
}

unsigned getUnversionedInfoSize(const FieldInfo &FI) {
return getVariableInfoSize(FI);
}

void emitUnversionedInfo(raw_ostream &OS, const FieldInfo &FI) {
emitVariableInfo(OS, FI);
}
};
} // namespace

void APINotesWriter::Implementation::writeFieldBlock(
llvm::BitstreamWriter &Stream) {
llvm::BCBlockRAII Scope(Stream, FIELD_BLOCK_ID, 3);

if (Fields.empty())
return;

{
llvm::SmallString<4096> HashTableBlob;
uint32_t Offset;
{
llvm::OnDiskChainedHashTableGenerator<FieldTableInfo> Generator;
for (auto &FD : Fields)
Generator.insert(FD.first, FD.second);

llvm::raw_svector_ostream BlobStream(HashTableBlob);
// Make sure that no bucket is at offset 0
llvm::support::endian::write<uint32_t>(BlobStream, 0,
llvm::endianness::little);
Offset = Generator.Emit(BlobStream);
}

field_block::FieldDataLayout FieldData(Stream);
FieldData.emit(Scratch, Offset, HashTableBlob);
}
}

namespace {
/// Used to serialize the on-disk Objective-C selector table.
class ObjCSelectorTableInfo {
Expand Down Expand Up @@ -1423,6 +1488,14 @@ void APINotesWriter::addCXXMethod(ContextID CtxID, llvm::StringRef Name,
Implementation->CXXMethods[Key].push_back({SwiftVersion, Info});
}

void APINotesWriter::addField(ContextID CtxID, llvm::StringRef Name,
const FieldInfo &Info,
VersionTuple SwiftVersion) {
IdentifierID NameID = Implementation->getIdentifier(Name);
SingleDeclTableKey Key(CtxID.Value, NameID);
Implementation->Fields[Key].push_back({SwiftVersion, Info});
}

void APINotesWriter::addGlobalVariable(std::optional<Context> Ctx,
llvm::StringRef Name,
const GlobalVariableInfo &Info,
Expand Down
64 changes: 52 additions & 12 deletions clang/lib/APINotes/APINotesYAMLCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,38 @@ template <> struct ScalarEnumerationTraits<EnumConvenienceAliasKind> {
} // namespace yaml
} // namespace llvm

namespace {
struct Field {
StringRef Name;
std::optional<NullabilityKind> Nullability;
AvailabilityItem Availability;
std::optional<bool> SwiftPrivate;
StringRef SwiftName;
StringRef Type;
};

typedef std::vector<Field> FieldsSeq;
} // namespace

LLVM_YAML_IS_SEQUENCE_VECTOR(Field)

namespace llvm {
namespace yaml {
template <> struct MappingTraits<Field> {
static void mapping(IO &IO, Field &F) {
IO.mapRequired("Name", F.Name);
IO.mapOptional("Nullability", F.Nullability, std::nullopt);
IO.mapOptional("Availability", F.Availability.Mode,
APIAvailability::Available);
IO.mapOptional("AvailabilityMsg", F.Availability.Msg, StringRef(""));
IO.mapOptional("SwiftPrivate", F.SwiftPrivate);
IO.mapOptional("SwiftName", F.SwiftName, StringRef(""));
IO.mapOptional("Type", F.Type, StringRef(""));
}
};
} // namespace yaml
} // namespace llvm

namespace {
struct Tag;
typedef std::vector<Tag> TagsSeq;
Expand All @@ -425,6 +457,7 @@ struct Tag {
std::optional<EnumConvenienceAliasKind> EnumConvenienceKind;
std::optional<bool> SwiftCopyable;
FunctionsSeq Methods;
FieldsSeq Fields;

/// Tags that are declared within the current tag. Only the tags that have
/// corresponding API Notes will be listed.
Expand Down Expand Up @@ -463,6 +496,7 @@ template <> struct MappingTraits<Tag> {
IO.mapOptional("EnumKind", T.EnumConvenienceKind);
IO.mapOptional("SwiftCopyable", T.SwiftCopyable);
IO.mapOptional("Methods", T.Methods);
IO.mapOptional("Fields", T.Fields);
IO.mapOptional("Tags", T.Tags);
}
};
Expand Down Expand Up @@ -793,6 +827,16 @@ class YAMLConverter {
SwiftVersion);
}

template <typename T>
void convertVariable(const T &Entity, VariableInfo &VI) {
convertAvailability(Entity.Availability, VI, Entity.Name);
VI.setSwiftPrivate(Entity.SwiftPrivate);
VI.SwiftName = std::string(Entity.SwiftName);
if (Entity.Nullability)
VI.setNullabilityAudited(*Entity.Nullability);
VI.setType(std::string(Entity.Type));
}

void convertContext(std::optional<ContextID> ParentContextID, const Class &C,
ContextKind Kind, VersionTuple SwiftVersion) {
// Write the class.
Expand Down Expand Up @@ -848,14 +892,9 @@ class YAMLConverter {

// Translate from Property into ObjCPropertyInfo.
ObjCPropertyInfo PI;
convertAvailability(Property.Availability, PI, Property.Name);
PI.setSwiftPrivate(Property.SwiftPrivate);
PI.SwiftName = std::string(Property.SwiftName);
if (Property.Nullability)
PI.setNullabilityAudited(*Property.Nullability);
convertVariable(Property, PI);
if (Property.SwiftImportAsAccessors)
PI.setSwiftImportAsAccessors(*Property.SwiftImportAsAccessors);
PI.setType(std::string(Property.Type));

// Add both instance and class properties with this name.
if (Property.Kind) {
Expand Down Expand Up @@ -970,6 +1009,12 @@ class YAMLConverter {
CI, SwiftVersion);
Context TagCtx(TagCtxID, ContextKind::Tag);

for (const auto &Field : T.Fields) {
FieldInfo FI;
convertVariable(Field, FI);
Writer.addField(TagCtxID, Field.Name, FI, SwiftVersion);
}

for (const auto &CXXMethod : T.Methods) {
CXXMethodInfo MI;
convertFunction(CXXMethod, MI);
Expand Down Expand Up @@ -1037,12 +1082,7 @@ class YAMLConverter {
}

GlobalVariableInfo GVI;
convertAvailability(Global.Availability, GVI, Global.Name);
GVI.setSwiftPrivate(Global.SwiftPrivate);
GVI.SwiftName = std::string(Global.SwiftName);
if (Global.Nullability)
GVI.setNullabilityAudited(*Global.Nullability);
GVI.setType(std::string(Global.Type));
convertVariable(Global, GVI);
Writer.addGlobalVariable(Ctx, Global.Name, GVI, SwiftVersion);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/ARCMigrate/ARCMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ bool MigrationProcess::applyTransform(TransformFn trans,
for (Rewriter::buffer_iterator
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
llvm::RewriteBuffer &buf = I->second;
OptionalFileEntryRef file =
Ctx.getSourceManager().getFileEntryRefForID(FID);
assert(file);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ARCMigrate/ObjCMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using namespace clang;
using namespace arcmt;
using namespace ento;
using llvm::RewriteBuffer;

namespace {

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//===----------------------------------------------------------------------===//

#include "clang/AST/ASTContext.h"
#include "ByteCode/Context.h"
#include "CXXABI.h"
#include "Interp/Context.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTMutationListener.h"
Expand Down Expand Up @@ -3279,7 +3279,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,

case Type::MemberPointer: {
OS << "M";
const auto *MPT = T->getAs<MemberPointerType>();
const auto *MPT = T->castAs<MemberPointerType>();
encodeTypeForFunctionPointerAuth(Ctx, OS, QualType(MPT->getClass(), 0));
encodeTypeForFunctionPointerAuth(Ctx, OS, MPT->getPointeeType());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
#ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H
#define LLVM_CLANG_AST_INTERP_BOOLEAN_H

#include <cstddef>
#include <cstdint>
#include "Integral.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ComparisonCategories.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <cstdint>

namespace clang {
namespace interp {

/// Wrapper around boolean types.
class Boolean final {
private:
private:
/// Underlying boolean.
bool V;

public:
public:
/// Zero-initializes a boolean.
Boolean() : V(false) {}
explicit Boolean(bool V) : V(V) {}
Expand All @@ -44,6 +44,7 @@ class Boolean final {
Boolean operator-() const { return Boolean(V); }
Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); }
Boolean operator~() const { return Boolean(true); }
Boolean operator!() const { return Boolean(!V); }

template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
explicit operator Ty() const {
Expand Down Expand Up @@ -104,8 +105,7 @@ class Boolean final {

static Boolean zero() { return from(false); }

template <typename T>
static Boolean from(T Value, unsigned NumBits) {
template <typename T> static Boolean from(T Value, unsigned NumBits) {
return Boolean(Value);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Boolean &B) {
return OS;
}

} // namespace interp
} // namespace clang
} // namespace interp
} // namespace clang

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ void ByteCodeEmitter::emitLabel(LabelTy Label) {
const size_t Target = Code.size();
LabelOffsets.insert({Label, Target});

if (auto It = LabelRelocs.find(Label);
It != LabelRelocs.end()) {
if (auto It = LabelRelocs.find(Label); It != LabelRelocs.end()) {
for (unsigned Reloc : It->second) {
using namespace llvm::support;

Expand All @@ -228,8 +227,7 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
assert(aligned(Position));

// If target is known, compute jump offset.
if (auto It = LabelOffsets.find(Label);
It != LabelOffsets.end())
if (auto It = LabelOffsets.find(Label); It != LabelOffsets.end())
return It->second - Position;

// Otherwise, record relocation and return dummy offset.
Expand Down Expand Up @@ -308,7 +306,8 @@ void emit(Program &P, std::vector<std::byte> &Code, const IntegralAP<true> &Val,
}

template <typename... Tys>
bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo &SI) {
bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
const SourceInfo &SI) {
bool Success = true;

// The opcode is followed by arguments. The source info is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ByteCodeEmitter {

/// Emits an opcode.
template <typename... Tys>
bool emitOp(Opcode Op, const Tys &... Args, const SourceInfo &L);
bool emitOp(Opcode Op, const Tys &...Args, const SourceInfo &L);

protected:
#define GET_LINK_PROTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {

case CK_NullToPointer:
case CK_NullToMemberPointer: {
if (!this->discard(SubExpr))
return false;
if (DiscardResult)
return true;

Expand Down Expand Up @@ -3722,7 +3724,8 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl *VD,
}

template <class Emitter>
VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Toplevel) {
VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
bool Toplevel) {
// We don't know what to do with these, so just return false.
if (VD->getType().isNull())
return false;
Expand Down Expand Up @@ -5111,7 +5114,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
if (!this->visitBool(SubExpr))
return false;

if (!this->emitInvBool(E))
if (!this->emitInv(E))
return false;

if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
Expand All @@ -5124,7 +5127,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
if (!this->visit(SubExpr))
return false;
return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
case UO_Plus: // +x
case UO_Plus: // +x
if (!T)
return this->emitError(E);

Expand Down Expand Up @@ -5230,7 +5233,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
return false;
if (!this->emitComplexBoolCast(SubExpr))
return false;
if (!this->emitInvBool(E))
if (!this->emitInv(E))
return false;
if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
return this->emitCast(PT_Bool, ET, E);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ std::optional<PrimType> Context::classify(QualType T) const {
return PT_Uint16;
case 8:
return PT_Uint8;
case 1:
// Might happen for enum types.
return PT_Bool;
default:
return PT_IntAP;
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct Descriptor final {
/// Returns the allocated size, including metadata.
unsigned getAllocSize() const { return AllocSize; }
/// returns the size of an element when the structure is viewed as an array.
unsigned getElemSize() const { return ElemSize; }
unsigned getElemSize() const { return ElemSize; }
/// Returns the size of the metadata.
unsigned getMetadataSize() const { return MDSize; }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
return std::move(this->EvalResult);
}

void EvalEmitter::emitLabel(LabelTy Label) {
CurrentLabel = Label;
}
void EvalEmitter::emitLabel(LabelTy Label) { CurrentLabel = Label; }

EvalEmitter::LabelTy EvalEmitter::getLabel() { return NextLabel++; }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,
llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
llvm::SmallVectorImpl<unsigned> &&ParamOffsets,
bool HasThisPointer, bool HasRVO, bool UnevaluatedBuiltin)
: P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
HasRVO(HasRVO), Variadic(F->isVariadic()),
: P(P), F(F), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)),
Params(std::move(Params)), ParamOffsets(std::move(ParamOffsets)),
HasThisPointer(HasThisPointer), HasRVO(HasRVO), Variadic(F->isVariadic()),
IsUnevaluatedBuiltin(UnevaluatedBuiltin) {}

Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ class Function final {
return F->getQualifiedNameAsString();
}

/// Returns the location.
SourceLocation getLoc() const { return Loc; }

/// Returns a parameter descriptor.
ParamDescriptor getParamDescriptor(unsigned Offset) const;

Expand Down Expand Up @@ -235,8 +232,6 @@ class Function final {

/// Program reference.
Program &P;
/// Location of the executed code.
SourceLocation Loc;
/// Declaration this function was compiled from.
const FunctionDecl *F;
/// Local area size: storage + metadata.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_H
#define LLVM_CLANG_AST_INTERP_INTEGRAL_H

#include "clang/AST/ComparisonCategories.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ComparisonCategories.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -33,14 +33,30 @@ template <bool Signed> class IntegralAP;

// Helper structure to select the representation.
template <unsigned Bits, bool Signed> struct Repr;
template <> struct Repr<8, false> { using Type = uint8_t; };
template <> struct Repr<16, false> { using Type = uint16_t; };
template <> struct Repr<32, false> { using Type = uint32_t; };
template <> struct Repr<64, false> { using Type = uint64_t; };
template <> struct Repr<8, true> { using Type = int8_t; };
template <> struct Repr<16, true> { using Type = int16_t; };
template <> struct Repr<32, true> { using Type = int32_t; };
template <> struct Repr<64, true> { using Type = int64_t; };
template <> struct Repr<8, false> {
using Type = uint8_t;
};
template <> struct Repr<16, false> {
using Type = uint16_t;
};
template <> struct Repr<32, false> {
using Type = uint32_t;
};
template <> struct Repr<64, false> {
using Type = uint64_t;
};
template <> struct Repr<8, true> {
using Type = int8_t;
};
template <> struct Repr<16, true> {
using Type = int16_t;
};
template <> struct Repr<32, true> {
using Type = int32_t;
};
template <> struct Repr<64, true> {
using Type = int64_t;
};

/// Wrapper around numeric types.
///
Expand Down Expand Up @@ -159,12 +175,8 @@ template <unsigned Bits, bool Signed> class Integral final {

void print(llvm::raw_ostream &OS) const { OS << V; }

static Integral min(unsigned NumBits) {
return Integral(Min);
}
static Integral max(unsigned NumBits) {
return Integral(Max);
}
static Integral min(unsigned NumBits) { return Integral(Min); }
static Integral max(unsigned NumBits) { return Integral(Max); }

template <typename ValT> static Integral from(ValT Value) {
if constexpr (std::is_integral<ValT>::value)
Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 33 additions & 16 deletions clang/lib/AST/Interp/Interp.h → clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,9 @@ inline bool Divf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
// Inv
//===----------------------------------------------------------------------===//

template <PrimType Name, class T = typename PrimConv<Name>::T>
bool Inv(InterpState &S, CodePtr OpPC) {
using BoolT = PrimConv<PT_Bool>::T;
const T &Val = S.Stk.pop<T>();
const unsigned Bits = Val.bitWidth();
Boolean R;
Boolean::inv(BoolT::from(Val, Bits), &R);

S.Stk.push<BoolT>(R);
inline bool Inv(InterpState &S, CodePtr OpPC) {
const auto &Val = S.Stk.pop<Boolean>();
S.Stk.push<Boolean>(!Val);
return true;
}

Expand Down Expand Up @@ -1226,7 +1220,7 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
bool GetField(InterpState &S, CodePtr OpPC, uint32_t I) {
const Pointer &Obj = S.Stk.peek<Pointer>();
if (!CheckNull(S, OpPC, Obj, CSK_Field))
return false;
return false;
if (!CheckRange(S, OpPC, Obj, CSK_Field))
return false;
const Pointer &Field = Obj.atField(I);
Expand Down Expand Up @@ -1542,7 +1536,7 @@ inline bool GetPtrActiveField(InterpState &S, CodePtr OpPC, uint32_t Off) {
}

inline bool GetPtrActiveThisField(InterpState &S, CodePtr OpPC, uint32_t Off) {
if (S.checkingPotentialConstantExpression())
if (S.checkingPotentialConstantExpression())
return false;
const Pointer &This = S.Current->getThis();
if (!CheckThis(S, OpPC, This))
Expand Down Expand Up @@ -1853,6 +1847,17 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
if (!CheckArray(S, OpPC, Ptr))
return false;

// This is much simpler for integral pointers, so handle them first.
if (Ptr.isIntegralPointer()) {
uint64_t V = Ptr.getIntegerRepresentation();
uint64_t O = static_cast<uint64_t>(Offset) * Ptr.elemSize();
if constexpr (Op == ArithOp::Add)
S.Stk.push<Pointer>(V + O, Ptr.asIntPointer().Desc);
else
S.Stk.push<Pointer>(V - O, Ptr.asIntPointer().Desc);
return true;
}

uint64_t MaxIndex = static_cast<uint64_t>(Ptr.getNumElems());
uint64_t Index;
if (Ptr.isOnePastEnd())
Expand Down Expand Up @@ -2053,7 +2058,7 @@ template <PrimType TIn, PrimType TOut> bool Cast(InterpState &S, CodePtr OpPC) {
/// 1) Pops a Floating from the stack.
/// 2) Pushes a new floating on the stack that uses the given semantics.
inline bool CastFP(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem,
llvm::RoundingMode RM) {
llvm::RoundingMode RM) {
Floating F = S.Stk.pop<Floating>();
Floating Result = F.toSemantics(Sem, RM);
S.Stk.push<Floating>(Result);
Expand Down Expand Up @@ -2313,9 +2318,9 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS) {
if (!S.noteUndefinedBehavior())
return false;
RHS = -RHS;
return DoShift < LT, RT,
Dir == ShiftDir::Left ? ShiftDir::Right
: ShiftDir::Left > (S, OpPC, LHS, RHS);
return DoShift<LT, RT,
Dir == ShiftDir::Left ? ShiftDir::Right : ShiftDir::Left>(
S, OpPC, LHS, RHS);
}

if constexpr (Dir == ShiftDir::Left) {
Expand Down Expand Up @@ -2354,6 +2359,17 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS) {
LT::AsUnsigned::from(RHS, Bits), Bits, &R);
}

// We did the shift above as unsigned. Restore the sign bit if we need to.
if constexpr (Dir == ShiftDir::Right) {
if (LHS.isSigned() && LHS.isNegative()) {
typename LT::AsUnsigned SignBit;
LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(1, Bits),
LT::AsUnsigned::from(Bits - 1, Bits), Bits,
&SignBit);
LT::AsUnsigned::bitOr(R, SignBit, Bits, &R);
}
}

S.Stk.push<LT>(LT::from(R));
return true;
}
Expand Down Expand Up @@ -2467,7 +2483,8 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) {
}

template <PrimType Name, class T = typename PrimConv<Name>::T>
inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex, uint32_t DestIndex, uint32_t Size) {
inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex,
uint32_t DestIndex, uint32_t Size) {
const auto &SrcPtr = S.Stk.pop<Pointer>();
const auto &DestPtr = S.Stk.peek<Pointer>();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#define LLVM_CLANG_AST_INTERP_BLOCK_H

#include "Descriptor.h"
#include "clang/AST/ComparisonCategories.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ComparisonCategories.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/raw_ostream.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,51 @@ static bool interp__builtin_iszero(InterpState &S, CodePtr OpPC,
return true;
}

static bool interp__builtin_signbit(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame, const Function *F,
const CallExpr *Call) {
const Floating &Arg = S.Stk.peek<Floating>();

pushInteger(S, Arg.isNegative(), Call->getType());
return true;
}

static bool interp_floating_comparison(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *F,
const CallExpr *Call) {
const Floating &RHS = S.Stk.peek<Floating>();
const Floating &LHS = S.Stk.peek<Floating>(align(2u * primSize(PT_Float)));
unsigned ID = F->getBuiltinID();

pushInteger(
S,
[&] {
switch (ID) {
case Builtin::BI__builtin_isgreater:
return LHS > RHS;
case Builtin::BI__builtin_isgreaterequal:
return LHS >= RHS;
case Builtin::BI__builtin_isless:
return LHS < RHS;
case Builtin::BI__builtin_islessequal:
return LHS <= RHS;
case Builtin::BI__builtin_islessgreater: {
ComparisonCategoryResult cmp = LHS.compare(RHS);
return cmp == ComparisonCategoryResult::Less ||
cmp == ComparisonCategoryResult::Greater;
}
case Builtin::BI__builtin_isunordered:
return LHS.compare(RHS) == ComparisonCategoryResult::Unordered;
default:
llvm_unreachable("Unexpected builtin ID: Should be a floating point "
"comparison function");
}
}(),
Call->getType());
return true;
}

/// First parameter to __builtin_isfpclass is the floating value, the
/// second one is an integral value.
static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
Expand Down Expand Up @@ -1313,6 +1358,21 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
if (!interp__builtin_iszero(S, OpPC, Frame, F, Call))
return false;
break;
case Builtin::BI__builtin_signbit:
case Builtin::BI__builtin_signbitf:
case Builtin::BI__builtin_signbitl:
if (!interp__builtin_signbit(S, OpPC, Frame, F, Call))
return false;
break;
case Builtin::BI__builtin_isgreater:
case Builtin::BI__builtin_isgreaterequal:
case Builtin::BI__builtin_isless:
case Builtin::BI__builtin_islessequal:
case Builtin::BI__builtin_islessgreater:
case Builtin::BI__builtin_isunordered:
if (!interp_floating_comparison(S, OpPC, Frame, F, Call))
return false;
break;
case Builtin::BI__builtin_isfpclass:
if (!interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx,
if (!Ty->isReferenceType())
OS << "&";
llvm::SmallVector<Pointer, 2> Levels;
for (Pointer F = P; !F.isRoot(); ) {
for (Pointer F = P; !F.isRoot();) {
Levels.push_back(F);
F = F.isArrayElement() ? F.getArray().expand() : F.getBase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class InterpFrame final : public Frame {

/// Mutates a local copy of a parameter.
template <typename T> void setParam(unsigned Offset, const T &Value) {
getParamPointer(Offset).deref<T>() = Value;
getParamPointer(Offset).deref<T>() = Value;
}

/// Returns a pointer to an argument - lazily creates a block.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
using namespace clang;
using namespace clang::interp;

InterpStack::~InterpStack() {
clear();
}
InterpStack::~InterpStack() { clear(); }

void InterpStack::clear() {
if (Chunk && Chunk->Next)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InterpStack final {
~InterpStack();

/// Constructs a value in place on the top of the stack.
template <typename T, typename... Tys> void push(Tys &&... Args) {
template <typename T, typename... Tys> void push(Tys &&...Args) {
new (grow(aligned_size<T>())) T(std::forward<Tys>(Args)...);
#ifndef NDEBUG
ItemTypes.push_back(toPrimType<T>());
Expand Down Expand Up @@ -153,8 +153,7 @@ class InterpStack final {
template <typename T> static constexpr PrimType toPrimType() {
if constexpr (std::is_same_v<T, Pointer>)
return PT_Ptr;
else if constexpr (std::is_same_v<T, bool> ||
std::is_same_v<T, Boolean>)
else if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, Boolean>)
return PT_Bool;
else if constexpr (std::is_same_v<T, int8_t> ||
std::is_same_v<T, Integral<8, true>>)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace interp {
std::optional<Pointer> MemberPointer::toPointer(const Context &Ctx) const {
if (!Dcl || isa<FunctionDecl>(Dcl))
return Base;
const FieldDecl *FD = cast<FieldDecl>(Dcl);
assert(FD);
assert((isa<FieldDecl, IndirectFieldDecl>(Dcl)));

if (!Base.isBlockPointer())
return std::nullopt;
Expand All @@ -31,24 +30,36 @@ std::optional<Pointer> MemberPointer::toPointer(const Context &Ctx) const {
if (!BaseRecord)
return std::nullopt;

assert(BaseRecord);
if (FD->getParent() == BaseRecord->getDecl())
return CastedBase.atField(BaseRecord->getField(FD)->Offset);

const RecordDecl *FieldParent = FD->getParent();
const Record *FieldRecord = Ctx.getRecord(FieldParent);

unsigned Offset = 0;
Offset += FieldRecord->getField(FD)->Offset;
Offset += CastedBase.block()->getDescriptor()->getMetadataSize();

if (Offset > CastedBase.block()->getSize())
return std::nullopt;
if (const auto *FD = dyn_cast<FieldDecl>(Dcl)) {
if (FD->getParent() == BaseRecord->getDecl())
return CastedBase.atField(BaseRecord->getField(FD)->Offset);

if (const RecordDecl *BaseDecl = Base.getDeclPtr().getRecord()->getDecl();
BaseDecl != FieldParent)
Offset += Ctx.collectBaseOffset(FieldParent, BaseDecl);
const RecordDecl *FieldParent = FD->getParent();
const Record *FieldRecord = Ctx.getRecord(FieldParent);

Offset += FieldRecord->getField(FD)->Offset;
if (Offset > CastedBase.block()->getSize())
return std::nullopt;

if (const RecordDecl *BaseDecl = Base.getDeclPtr().getRecord()->getDecl();
BaseDecl != FieldParent)
Offset += Ctx.collectBaseOffset(FieldParent, BaseDecl);

} else {
const auto *IFD = cast<IndirectFieldDecl>(Dcl);

for (const NamedDecl *ND : IFD->chain()) {
const FieldDecl *F = cast<FieldDecl>(ND);
const RecordDecl *FieldParent = F->getParent();
const Record *FieldRecord = Ctx.getRecord(FieldParent);
Offset += FieldRecord->getField(F)->Offset;
}
}

assert(BaseRecord);
if (Offset > CastedBase.block()->getSize())
return std::nullopt;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ def PtrTypeClass : TypeClass {
let Types = [Ptr, FnPtr, MemberPtr];
}

def BoolTypeClass : TypeClass {
let Types = [Bool];
}

def NonPtrTypeClass : TypeClass {
let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float]);
}
Expand Down Expand Up @@ -574,11 +570,8 @@ def Shr : Opcode {
// Unary operators.
//===----------------------------------------------------------------------===//

// [Real] -> [Real]
def Inv: Opcode {
let Types = [BoolTypeClass];
let HasGroup = 1;
}
// [Bool] -> [Bool]
def Inv: Opcode;

// Increment and decrement.
def Inc: AluOpcode;
Expand Down
Loading