[all-commits] [llvm/llvm-project] b46fdd: [CodeGen] Implement [[likely]] and [[unlikely]] fo...

mordante via All-commits all-commits at lists.llvm.org
Sat Oct 31 09:52:08 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: b46fddf75fc27ee1545f00ab853d50b10c1d7ee6
      https://github.com/llvm/llvm-project/commit/b46fddf75fc27ee1545f00ab853d50b10c1d7ee6
  Author: Mark de Wever <koraq at xs4all.nl>
  Date:   2020-10-31 (Sat, 31 Oct 2020)

  Changed paths:
    M clang/include/clang/AST/Stmt.h
    M clang/include/clang/Basic/AttrDocs.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/AST/Stmt.cpp
    M clang/lib/CodeGen/CGStmt.cpp
    M clang/lib/CodeGen/CodeGenFunction.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    M clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
    A clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp

  Log Message:
  -----------
  [CodeGen] Implement [[likely]] and [[unlikely]] for while and for loop.

The attribute has no effect on a do statement since the path of execution
will always include its substatement.

It adds a diagnostic when the attribute is used on an infinite while loop
since the codegen omits the branch here. Since the likelihood attributes
have no effect on a do statement no diagnostic will be issued for
do [[unlikely]] {...} while(0);

Differential Revision: https://reviews.llvm.org/D89899


  Commit: b231396122f131ffaff5fc4ba36685a7df554aaa
      https://github.com/llvm/llvm-project/commit/b231396122f131ffaff5fc4ba36685a7df554aaa
  Author: Mark de Wever <koraq at xs4all.nl>
  Date:   2020-10-31 (Sat, 31 Oct 2020)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaStmt.cpp
    M clang/test/SemaCXX/attr-likelihood.cpp

  Log Message:
  -----------
  [Sema] Diagnose annotating `if constexpr` with a likelihood attribute

Adds a diagnostic when the user annotates an `if constexpr` with a
likelihood attribute. The `if constexpr` statement is evaluated at compile
time so the attribute has no effect. Annotating the accompanied `else`
with a likelihood attribute has the same effect as annotating a generic
statement. Since the attribute there is most likely not intended, a
diagnostic will be issued. Since the attributes can't conflict, the
"conflict" won't be diagnosed for an `if constexpr`.

Differential Revision: https://reviews.llvm.org/D90336


Compare: https://github.com/llvm/llvm-project/compare/ef6f6d1c1a28...b231396122f1


More information about the All-commits mailing list