diff options
Diffstat (limited to 'clang/docs')
-rw-r--r-- | clang/docs/ClangRepl.rst | 50 | ||||
-rw-r--r-- | clang/docs/HardwareAssistedAddressSanitizerDesign.rst | 3 | ||||
-rw-r--r-- | clang/docs/LanguageExtensions.rst | 24 | ||||
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 29 | ||||
-rw-r--r-- | clang/docs/UsersManual.rst | 119 | ||||
-rw-r--r-- | clang/docs/analyzer/checkers.rst | 17 | ||||
-rw-r--r-- | clang/docs/analyzer/checkers/storetoimmutable_example.cpp | 21 | ||||
-rw-r--r-- | clang/docs/index.rst | 1 |
8 files changed, 193 insertions, 71 deletions
diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index 5399036..e7e8630 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -159,8 +159,29 @@ Lamdas: clang-repl> welcome(); Welcome to REPL -Using Dynamic Library: -====================== +Comments: +========= + +.. code-block:: text + + clang-repl> // Comments in Clang-Repl + clang-repl> /* Comments in Clang-Repl */ + +Built in Commands: +================== +clang-repl has some special commands that are of the form ``%<something>``. To list all these commands, use the ``%help`` command: + +Help: +----- +The ``%help`` command lists all built in clang-repl commands. + +.. code-block:: text + + clang-repl> %help + +Using Dynamic Libraries: +------------------------ +The ``%lib`` command links a dynamic library. .. code-block:: text @@ -189,21 +210,30 @@ Using Dynamic Library: clang++-17 -c -o print.o print.cpp clang-17 -shared print.o -o print.so -Comments: -========= +Undo: +----- +The ``%undo`` command undoes the previous input. .. code-block:: text - clang-repl> // Comments in Clang-Repl - clang-repl> /* Comments in Clang-Repl */ + clang-repl> int a = 1; a + (int) 1 + clang-repl> %undo + clang-repl> a + In file included from <<< inputs >>>:1: + input_line_2:1:1: error: use of undeclared identifier 'a' + 1 | a + * | ^ + error: Parsing failed. - -Closure or Termination: -======================= +Quit: +----- +The ``%quit`` command terminates clang-repl. .. code-block:: text - clang-repl>%quit + clang-repl> %quit + Just like Clang, Clang-Repl can be integrated in existing applications as a library diff --git a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst index 20db41c..014d103 100644 --- a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst +++ b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst @@ -291,7 +291,7 @@ implement page aliasing. Related Work ============ -* `SPARC ADI`_ implements a similar tool mostly in hardware. +* `SPARC ADI`_ and `Arm MTE`_ implement a similar tool mostly in hardware. * `Effective and Efficient Memory Protection Using Dynamic Tainting`_ discusses similar approaches ("lock & key"). * `Watchdog`_ discussed a heavier, but still somewhat similar @@ -302,6 +302,7 @@ Related Work .. _Watchdog: https://www.cis.upenn.edu/acg/papers/isca12_watchdog.pdf .. _Effective and Efficient Memory Protection Using Dynamic Tainting: https://www.cc.gatech.edu/~orso/papers/clause.doudalis.orso.prvulovic.pdf .. _SPARC ADI: https://lazytyped.blogspot.com/2017/09/getting-started-with-adi.html +.. _Arm MTE: https://developer.arm.com/documentation/108035/0100/Introduction-to-the-Memory-Tagging-Extension .. _AddressSanitizer paper: https://www.usenix.org/system/files/conference/atc12/atc12-final39.pdf .. _Address Tagging: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/ch12s05s01.html .. _Linear Address Masking: https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 29ef20f..b5bb198 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -2018,7 +2018,7 @@ even if there is no valid ``std::tuple_element`` specialization or suitable Blocks ====== -The syntax and high level language feature description is in +The syntax and high-level language feature description is in :doc:`BlockLanguageSpec<BlockLanguageSpec>`. Implementation and ABI details for the clang implementation are in :doc:`Block-ABI-Apple<Block-ABI-Apple>`. @@ -2088,7 +2088,7 @@ producing an object with the following member functions constexpr size_t size() const; such as ``std::string``, ``std::string_view``, ``std::vector<char>``. -This mechanism follow the same rules as ``static_assert`` messages in +This mechanism follows the same rules as ``static_assert`` messages in C++26, see ``[dcl.pre]/p12``. Query for this feature with ``__has_extension(gnu_asm_constexpr_strings)``. @@ -2335,7 +2335,7 @@ Objective-C Autosynthesis of Properties Clang provides support for autosynthesis of declared properties. Using this feature, clang provides default synthesis of those properties not declared -@dynamic and not having user provided backing getter and setter methods. +@dynamic and not having user-provided backing getter and setter methods. ``__has_feature(objc_default_synthesize_properties)`` checks for availability of this feature in version of clang being used. @@ -2349,7 +2349,7 @@ In Objective-C, functions and methods are generally assumed to follow the <https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html>`_ conventions for ownership of object arguments and return values. However, there are exceptions, and so Clang provides attributes -to allow these exceptions to be documented. This are used by ARC and the +to allow these exceptions to be documented. These are used by ARC and the `static analyzer <https://clang-analyzer.llvm.org>`_ Some exceptions may be better described using the ``objc_method_family`` attribute instead. @@ -2575,7 +2575,7 @@ Such functionality is not conformant and does not guarantee to compile correctly in any circumstances. It can be used if: - the kernel source does not contain call expressions to (member-) function - pointers, or virtual functions. For example this extension can be used in + pointers, or virtual functions. For example, this extension can be used in metaprogramming algorithms to be able to specify/detect types generically. - the generated kernel binary does not contain indirect calls because they @@ -2613,7 +2613,7 @@ functions with variadic prototypes do not get generated in binary e.g. the variadic prototype is used to specify a function type with any number of arguments in metaprogramming algorithms in C++ for OpenCL. -This extensions can also be used when the kernel code is intended for targets +This extension can also be used when the kernel code is intended for targets supporting the variadic arguments e.g. majority of CPU targets. **Example of Use**: @@ -2702,7 +2702,7 @@ address space qualifiers, therefore, other type qualifiers such as Legacy 1.x atomics with generic address space --------------------------------------------- -Clang allows use of atomic functions from the OpenCL 1.x standards +Clang allows the use of atomic functions from the OpenCL 1.x standards with the generic address space pointer in C++ for OpenCL mode. This is a non-portable feature and might not be supported by all @@ -2833,7 +2833,7 @@ to a possibly overlapping destination region. It takes five arguments. The first argument is the destination WebAssembly table, and the second argument is the source WebAssembly table. The third argument is the destination index from where the copy starts, the fourth argument is the -source index from there the copy starts, and the fifth and last argument +source index from where the copy starts, and the fifth and last argument is the number of elements to copy. It returns nothing. .. code-block:: c++ @@ -3133,7 +3133,7 @@ Query for this feature with ``__has_builtin(__builtin_get_vtable_pointer)``. ------------------------------------ ``__builtin_call_with_static_chain`` is used to perform a static call while -setting updating the static chain register. +updating the static chain register. **Syntax**: @@ -3245,7 +3245,7 @@ Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``. The ``__builtin_cpu_supports`` function detects if the run-time CPU supports features specified in string argument. It returns a positive integer if all features are supported and 0 otherwise. Feature names are target specific. On -AArch64 features are combined using ``+`` like this +AArch64, features are combined using ``+`` like this ``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``. If a feature name is not supported, Clang will issue a warning and replace builtin by the constant 0. @@ -3465,7 +3465,7 @@ Query for this feature with ``__has_builtin(__builtin_convertvector)``. **Description**: The '``__builtin_bitreverse``' family of builtins is used to reverse -the bitpattern of an integer value; for example ``0b10110110`` becomes +the bitpattern of an integer value; for example, ``0b10110110`` becomes ``0b01101101``. These builtins can be used within constant expressions. ``__builtin_rotateleft`` @@ -3970,7 +3970,7 @@ the debugging experience. ``__builtin_allow_runtime_check`` returns true if the check at the current program location should be executed. It is expected to be used to implement -``assert`` like checks which can be safely removed by optimizer. +``assert`` like checks which can be safely removed by the optimizer. **Syntax**: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 247d784..2a95d1e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -45,6 +45,26 @@ C++ Specific Potentially Breaking Changes regressions if your build system supports two-phase compilation model but haven't support reduced BMI or it is a compiler bug or a bug in users code. +- Clang now correctly diagnoses during constant expression evaluation undefined behavior due to member + pointer access to a member which is not a direct or indirect member of the most-derived object + of the accessed object but is instead located directly in a sibling class to one of the classes + along the inheritance hierarchy of the most-derived object as ill-formed. + Other scenarios in which the member is not member of the most derived object were already + diagnosed previously. (#GH150709) + + .. code-block:: c++ + + struct A {}; + struct B : A {}; + struct C : A { constexpr int foo() const { return 1; } }; + constexpr A a; + constexpr B b; + constexpr C c; + constexpr auto mp = static_cast<int(A::*)() const>(&C::foo); + static_assert((a.*mp)() == 1); // continues to be rejected + static_assert((b.*mp)() == 1); // newly rejected + static_assert((c.*mp)() == 1); // accepted + ABI Changes in This Version --------------------------- @@ -123,6 +143,8 @@ Improvements to Clang's diagnostics Moved the warning for a missing (though implied) attribute on a redeclaration into this group. Added a new warning in this group for the case where the attribute is missing/implicit on an override of a virtual method. +- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right + parenthesis when diagnosing malformed fold expressions. (#GH151787) Improvements to Clang's time-trace ---------------------------------- @@ -142,12 +164,16 @@ Bug Fixes in This Version Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- Fix an ambiguous reference to the builtin `type_info` (available when using + `-fms-compatibility`) with modules. (#GH38400) Bug Fixes to Attribute Support ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods. (#GH141504) +- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with + ``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520) Bug Fixes to C++ Support ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -196,6 +222,9 @@ LoongArch Support RISC-V Support ^^^^^^^^^^^^^^ +- Add support for `__attribute__((interrupt("rnmi")))` to be used with the `Smrnmi` extension. + With this the `Smrnmi` extension is fully supported. + CUDA/HIP Language Changes ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index af0a874..c703929 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -35,11 +35,12 @@ which includes :ref:`C <c>`, :ref:`Objective-C <objc>`, :ref:`C++ <cxx>`, and language-specific information, please see the corresponding language specific section: -- :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, ISO C94 (C89+AMD1), ISO - C99 (+TC1, TC2, TC3). +- :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, C94 (C89+AMD1), C99 (+TC1, + TC2, TC3), C11, C17, C23, and C2y. - :ref:`Objective-C Language <objc>`: ObjC 1, ObjC 2, ObjC 2.1, plus variants depending on base language. -- :ref:`C++ Language <cxx>` +- :ref:`C++ Language <cxx>`: C++98, C++03, C++11, C++14, C++17, C++20, C++23, + and C++26. - :ref:`Objective C++ Language <objcxx>` - :ref:`OpenCL Kernel Language <opencl>`: OpenCL C 1.0, 1.1, 1.2, 2.0, 3.0, and C++ for OpenCL 1.0 and 2021. @@ -60,29 +61,55 @@ features that depend on what CPU architecture or operating system is being compiled for. Please see the :ref:`Target-Specific Features and Limitations <target_features>` section for more details. -The rest of the introduction introduces some basic :ref:`compiler -terminology <terminology>` that is used throughout this manual and -contains a basic :ref:`introduction to using Clang <basicusage>` as a -command line compiler. - .. _terminology: Terminology ----------- +* Lexer -- the part of the compiler responsible for converting source code into + abstract representations called tokens. +* Preprocessor -- the part of the compiler responsible for in-place textual + replacement of source constructs. When the lexer is required to produce a + token, it will run the preprocessor while determining which token to produce. + In other words, when the lexer encounters something like `#include` or a macro + name, the preprocessor will be used to perform the inclusion or expand the + macro name into its replacement list, and return the resulting non-preprocessor + token. +* Parser -- the part of the compiler responsible for determining syntactic + correctness of the source code. The parser will request tokens from the lexer + and after performing semantic analysis of the production, generates an + abstract representation of the source called an AST. +* Sema -- the part of the compiler responsible for determining semantic + correctness of the source code. It is closely related to the parser and is + where many diagnostics are produced. +* Diagnostic -- a message to the user about properties of the source code. For + example, errors or warnings and their associated notes. +* Undefined behavior -- behavior for which the standard imposes no requirements + on how the code behaves. Generally speaking, undefined behavior is a bug in + the user's code. However, it can also be a place for the compiler to define + the behavior, called an extension. +* Optimizer -- the part of the compiler responsible for transforming code to + have better performance characteristics without changing the semantics of how + the code behaves. Note, the optimizer assumes the code has no undefined + behavior, so if the code does contain undefined behavior, it will often behave + differently depending on which optimization level is enabled. +* Frontend -- the Lexer, Preprocessor, Parser, Sema, and LLVM IR code generation + parts of the compiler. +* Middle-end -- a term used for the of the subset of the backend that does + (typically not target specific) optimizations prior to assembly code + generation. +* Backend -- the parts of the compiler which run after LLVM IR code generation, + such as the optimizer and generation of assembly code. + +See the :doc:`InternalsManual` for more details about the internal construction +of the compiler. + +Support +------- +Clang releases happen roughly `every six months <https://llvm.org/docs/HowToReleaseLLVM.html#annual-release-schedule>`_. +Only the current public release is officially supported. Bug-fix releases for +the current release will be produced on an as-needed basis, but bug fixes are +not backported to releases older than the current one. -Front end, parser, backend, preprocessor, undefined behavior, -diagnostic, optimizer - -.. _basicusage: - -Basic Usage ------------ - -Intro to how to use a C compiler for newbies. - -compile + link compile then link debug info enabling optimizations -picking a language to use, defaults to C17 by default. Autosenses based -on extension. using a makefile Command Line Options ==================== @@ -3797,8 +3824,8 @@ This environment variable does not affect the options added by the config files. C Language Features =================== -The support for standard C in clang is feature-complete except for the -C99 floating-point pragmas. +The support for standard C in Clang is mostly feature-complete, see the `C +status page <https://clang.llvm.org/c_status.html>`_ for more details. Extensions supported by clang ----------------------------- @@ -3883,23 +3910,10 @@ GCC extensions not implemented yet ---------------------------------- clang tries to be compatible with gcc as much as possible, but some gcc -extensions are not implemented yet: +extensions are not implemented: - clang does not support decimal floating point types (``_Decimal32`` and friends) yet. -- clang does not support nested functions; this is a complex feature - which is infrequently used, so it is unlikely to be implemented - anytime soon. In C++11 it can be emulated by assigning lambda - functions to local variables, e.g: - - .. code-block:: cpp - - auto const local_function = [&](int parameter) { - // Do something - }; - ... - local_function(1); - - clang only supports global register variables when the register specified is non-allocatable (e.g. the stack pointer). Support for general global register variables is unlikely to be implemented soon because it requires @@ -3914,18 +3928,13 @@ extensions are not implemented yet: that because clang pretends to be like GCC 4.2, and this extension was introduced in 4.3, the glibc headers will not try to use this extension with clang at the moment. -- clang does not support the gcc extension for forward-declaring - function parameters; this has not shown up in any real-world code - yet, though, so it might never be implemented. This is not a complete list; if you find an unsupported extension -missing from this list, please send an e-mail to cfe-dev. This list -currently excludes C++; see :ref:`C++ Language Features <cxx>`. Also, this -list does not include bugs in mostly-implemented features; please see -the `bug -tracker <https://bugs.llvm.org/buglist.cgi?quicksearch=product%3Aclang+component%3A-New%2BBugs%2CAST%2CBasic%2CDriver%2CHeaders%2CLLVM%2BCodeGen%2Cparser%2Cpreprocessor%2CSemantic%2BAnalyzer>`_ -for known existing bugs (FIXME: Is there a section for bug-reporting -guidelines somewhere?). +missing from this list, please file a `feature request <https://github.com/llvm/llvm-project/issues/>`_. +This list currently excludes C++; see :ref:`C++ Language Features <cxx>`. Also, +this list does not include bugs in mostly-implemented features; please see the +`issues list <https://github.com/llvm/llvm-project/issues/>`_ for known existing +bugs. Intentionally unsupported GCC extensions ---------------------------------------- @@ -3944,6 +3953,20 @@ Intentionally unsupported GCC extensions variable) will likely never be accepted by Clang. - clang does not support ``__builtin_apply`` and friends; this extension is extremely obscure and difficult to implement reliably. +- clang does not support the gcc extension for forward-declaring + function parameters. +- clang does not support nested functions; this is a complex feature which is + infrequently used, so it is unlikely to be implemented. In C++11 it can be + emulated by assigning lambda functions to local variables, e.g: + + .. code-block:: cpp + + auto const local_function = [&](int parameter) { + // Do something + }; + ... + local_function(1); + .. _c_ms: @@ -3983,7 +4006,7 @@ C++ Language Features clang fully implements all of standard C++98 except for exported templates (which were removed in C++11), all of standard C++11, -C++14, and C++17, and most of C++20. +C++14, and C++17, and most of C++20 and C++23. See the `C++ support in Clang <https://clang.llvm.org/cxx_status.html>`_ page for detailed information on C++ feature support across Clang versions. diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index 4e8b318..b2effad 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -3086,6 +3086,23 @@ Either the comparison is useless or there is division by zero. if (x == 0) { } // warn } +.. _alpha-core-StoreToImmutable: + +alpha.core.StoreToImmutable (C, C++) +"""""""""""""""""""""""""""""""""""" +Check for writes to immutable memory regions. This implements part of SEI CERT Rule ENV30-C. + +This checker detects attempts to write to memory regions that are marked as immutable, +including const variables, string literals, and other const-qualified memory. + +.. literalinclude:: checkers/storetoimmutable_example.cpp + :language: cpp + +**Solution** + +Avoid writing to const-qualified memory regions. If you need to modify the data, +remove the const qualifier from the original declaration or use a mutable copy. + alpha.cplusplus ^^^^^^^^^^^^^^^ diff --git a/clang/docs/analyzer/checkers/storetoimmutable_example.cpp b/clang/docs/analyzer/checkers/storetoimmutable_example.cpp new file mode 100644 index 0000000..bfd67ef --- /dev/null +++ b/clang/docs/analyzer/checkers/storetoimmutable_example.cpp @@ -0,0 +1,21 @@ +const int global_const = 42; + +struct TestStruct { + const int x; + int y; +}; + +void immutable_violation_examples() { + *(int *)&global_const = 100; // warn: Trying to write to immutable memory + + const int local_const = 42; + *(int *)&local_const = 43; // warn: Trying to write to immutable memory + + // NOTE: The following is reported in C++, but not in C, as the analyzer + // treats string literals as non-const char arrays in C mode. + char *ptr_to_str_literal = (char *)"hello"; + ptr_to_str_literal[0] = 'H'; // warn: Trying to write to immutable memory + + TestStruct s = {1, 2}; + *(int *)&s.x = 10; // warn: Trying to write to immutable memory +} diff --git a/clang/docs/index.rst b/clang/docs/index.rst index 4871d05..542bfc9 100644 --- a/clang/docs/index.rst +++ b/clang/docs/index.rst @@ -117,6 +117,7 @@ Design Documents OffloadingDesign PCHInternals ItaniumMangleAbiTags + ControlFlowIntegrityDesign HardwareAssistedAddressSanitizerDesign.rst ConstantInterpreter |