diff options
Diffstat (limited to 'clang/docs')
-rw-r--r-- | clang/docs/InternalsManual.rst | 61 | ||||
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 6 | ||||
-rw-r--r-- | clang/docs/analyzer/developer-docs/DebugChecks.rst | 16 |
3 files changed, 82 insertions, 1 deletions
diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst index bd74227..c677ddfa 100644 --- a/clang/docs/InternalsManual.rst +++ b/clang/docs/InternalsManual.rst @@ -2859,6 +2859,67 @@ This library is called by the :ref:`Parser library <Parser>` during parsing to do semantic analysis of the input. For valid programs, Sema builds an AST for parsed constructs. + +Concept Satisfaction Checking and Subsumption +--------------------------------------------- + +As per the C++ standard, constraints are `normalized <https://eel.is/c++draft/temp.constr.normal>`_ +and the normal form is used both for subsumption, and constraint checking. +Both depend on a parameter mapping that substitutes lazily. In particular, +we should not substitute in unused arguments. + +Clang follows the order of operations prescribed by the standard. + +Normalization happens prior to satisfaction and subsumption +and is handled by ``NormalizedConstraint``. + +Clang preserves in the normalized form intermediate concept-ids +(``ConceptIdConstraint``) This is used for diagnostics only and no substitution +happens in a ConceptIdConstraint if its expression is satisfied. + +The normal form of the associated constraints of a declaration is cached in +Sema::NormalizationCache such that it is only computed once. + +A ``NormalizedConstraint`` is a recursive data structure, where each node +contains a parameter mapping, represented by the indexes of all parameter +being used. + +Checking satisfaction is done by ``ConstraintSatisfactionChecker``, recursively +walking ``NormalizedConstraint``. At each level, we substitute the outermost +level of the template arguments referenced in the parameter mapping of a +normalized expression (``MultiLevelTemplateArgumentList``). + +For the following example, + +.. code-block:: c++ + + template <typename T> + concept A = __is_same(T, int); + + template <typename U> + concept B = A<U> && __is_same(U, int); + +The normal form of B is + +.. code-block:: c++ + + __is_same(T, int) /*T->U, innermost level*/ + && __is_same(U, int) {U->U} /*T->U, outermost level*/ + +After substitution in the mapping, we substitute in the constraint expression +using that copy of the ``MultiLevelTemplateArgumentList``, and then evaluate it. + +Because this is expensive, it is cached in +``UnsubstitutedConstraintSatisfactionCache``. + +Any error during satisfaction is recorded in ``ConstraintSatisfaction``. +for nested requirements, ``ConstraintSatisfaction`` is stored (including +diagnostics) in the AST, which is something we might want to improve. + +When an atomic constraint is not satified, we try to substitute into any +enclosing concept-id using the same mechanism described above, for +diagnostics purpose, and inject that in the ``ConstraintSatisfaction``. + .. _CodeGen: The CodeGen Library diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 145a83a..d2e5bd2 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -160,6 +160,10 @@ C++23 Feature Support C++20 Feature Support ^^^^^^^^^^^^^^^^^^^^^ +- Clang now normalizes constraints before checking whether they are satisfied, as mandated by the standard. + As a result, Clang no longer incorrectly diagnoses substitution failures in template arguments only + used in concept-ids, and produces better diagnostics for satisfaction failure. (#GH61811) (#GH135190) + C++17 Feature Support ^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +365,7 @@ Bug Fixes in This Version first parameter. (#GH113323). - Fixed a crash with incompatible pointer to integer conversions in designated initializers involving string literals. (#GH154046) -- Fix crash on CTAD for alias template. (#GH131342) +- Fix crash on CTAD for alias template. (#GH131342), (#GH131408) - Clang now emits a frontend error when a function marked with the `flatten` attribute calls another function that requires target features not enabled in the caller. This prevents a fatal error in the backend. diff --git a/clang/docs/analyzer/developer-docs/DebugChecks.rst b/clang/docs/analyzer/developer-docs/DebugChecks.rst index 767ef65..b3b9089 100644 --- a/clang/docs/analyzer/developer-docs/DebugChecks.rst +++ b/clang/docs/analyzer/developer-docs/DebugChecks.rst @@ -9,6 +9,22 @@ The analyzer contains a number of checkers which can aid in debugging. Enable them by using the "-analyzer-checker=" flag, followed by the name of the checker. +These checkers are especially useful when analyzing a specific function, using +the `-analyze-function` flag. The flag accepts the function name for C code, +like `-analyze-function=myfunction`. +For C++ code, due to overloading, the function name must include the +parameter list, like `-analyze-function="myfunction(int, _Bool)"`. + +Note that `bool` must be spelled as `_Bool` in the parameter list. +Refer to the output of `-analyzer-display-progress` to find the fully qualified +function name. + +There are cases when this name can still collide. For example with template +function instances with non-deducible (aka. explicit) template parameters. +In such cases, prefer passing a USR instead of a function name can resolve this +ambiguity, like this: `-analyze-function="c:@S@Window@F@overloaded#I#"`. + +Use the `clang-extdef-mapping` tool to find the USR for different functions. General Analysis Dumpers ======================== |