[clang] 7ef2bd4 - Relax MC/DC tests

2024-06-19 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-06-19T15:41:59+09:00
New Revision: 7ef2bd4e447280015803cff7fc91ec4dd09cd4b3

URL: 
https://github.com/llvm/llvm-project/commit/7ef2bd4e447280015803cff7fc91ec4dd09cd4b3
DIFF: 
https://github.com/llvm/llvm-project/commit/7ef2bd4e447280015803cff7fc91ec4dd09cd4b3.diff

LOG: Relax MC/DC tests

Added: 


Modified: 
clang/test/Profile/c-mcdc-class.cpp
clang/test/Profile/c-mcdc-logicalop-ternary.c
clang/test/Profile/c-mcdc-nested-ternary.c
clang/test/Profile/c-mcdc-not.c
clang/test/Profile/c-mcdc.c

Removed: 




diff  --git a/clang/test/Profile/c-mcdc-class.cpp 
b/clang/test/Profile/c-mcdc-class.cpp
index 748344194ef86..9a56d97d2dde9 100644
--- a/clang/test/Profile/c-mcdc-class.cpp
+++ b/clang/test/Profile/c-mcdc-class.cpp
@@ -59,8 +59,8 @@ Value::~Value(void) {
 // MCDCCTOR:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDCCTOR:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDCCTOR:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDCCTOR:  %mcdc.bits = load i8, ptr %[[LAB4]], align 1
-// MCDCCTOR:  %[[LAB8:[0-9]+]] = or i8 %mcdc.bits, %[[LAB7]]
+// MCDCCTOR:  %[[BITS:.+]] = load i8, ptr %[[LAB4]], align 1
+// MCDCCTOR:  %[[LAB8:[0-9]+]] = or i8 %[[BITS]], %[[LAB7]]
 // MCDCCTOR:  store i8 %[[LAB8]], ptr %[[LAB4]], align 1
 
 // MCDCDTOR: @__profbm__ZN5ValueD2Ev = private global [1 x i8] zeroinitializer
@@ -97,6 +97,6 @@ Value::~Value(void) {
 // MCDCDTOR:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDCDTOR:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDCDTOR:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDCDTOR:  %mcdc.bits = load i8, ptr %[[LAB4]], align 1
-// MCDCDTOR:  %[[LAB8:[0-9]+]] = or i8 %mcdc.bits, %[[LAB7]]
+// MCDCDTOR:  %[[BITS:.+]] = load i8, ptr %[[LAB4]], align 1
+// MCDCDTOR:  %[[LAB8:[0-9]+]] = or i8 %[[BITS]], %[[LAB7]]
 // MCDCDTOR:  store i8 %[[LAB8]], ptr %[[LAB4]], align 1

diff  --git a/clang/test/Profile/c-mcdc-logicalop-ternary.c 
b/clang/test/Profile/c-mcdc-logicalop-ternary.c
index 91174befb5fe5..18ce0b4e5dc14 100644
--- a/clang/test/Profile/c-mcdc-logicalop-ternary.c
+++ b/clang/test/Profile/c-mcdc-logicalop-ternary.c
@@ -25,7 +25,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDC:  %[[LAB8:mcdc.bits[0-9]*]] = load i8, ptr %[[LAB4]], align 1
+// MCDC:  %[[LAB8:.+]] = load i8, ptr %[[LAB4]], align 1
 // MCDC:  %[[LAB9:[0-9]+]] = or i8 %[[LAB8]], %[[LAB7]]
 // MCDC:  store i8 %[[LAB9]], ptr %[[LAB4]], align 1
 
@@ -42,7 +42,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDC:  %[[LAB8:mcdc.bits[0-9]*]] = load i8, ptr %[[LAB4]], align 1
+// MCDC:  %[[LAB8:.+]] = load i8, ptr %[[LAB4]], align 1
 // MCDC:  %[[LAB9:[0-9]+]] = or i8 %[[LAB8]], %[[LAB7]]
 // MCDC:  store i8 %[[LAB9]], ptr %[[LAB4]], align 1
 
@@ -55,7 +55,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDC:  %[[LAB8:mcdc.bits[0-9]*]] = load i8, ptr %[[LAB4]], align 1
+// MCDC:  %[[LAB8:.+]] = load i8, ptr %[[LAB4]], align 1
 // MCDC:  %[[LAB9:[0-9]+]] = or i8 %[[LAB8]], %[[LAB7]]
 // MCDC:  store i8 %[[LAB9]], ptr %[[LAB4]], align 1
 
@@ -72,6 +72,6 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDC:  %[[LAB8:mcdc.bits[0-9]*]] = load i8, ptr %[[LAB4]], align 1
+// MCDC:  %[[LAB8:.+]] = load i8, ptr %[[LAB4]], align 1
 // MCDC:  %[[LAB9:[0-9]+]] = or i8 %[[LAB8]], %[[LAB7]]
 // MCDC:  store i8 %[[LAB9]], ptr %[[LAB4]], align 1

diff  --git a/clang/test/Profile/c-mcdc-nested-ternary.c 
b/clang/test/Profile/c-mcdc-nested-ternary.c
index 8576ba39e583b..e8eadf73504a2 100644
--- a/clang/test/Profile/c-mcdc-nested-ternary.c
+++ b/clang/test/Profile/c-mcdc-nested-ternary.c
@@ -62,6 +62,6 @@ int test(int b, int c, int d, int e, int f) {
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
-// MCDC:  %mcdc.bits = load i8, ptr %[[LAB4]], align 1
-// MCDC:  %[[LAB8:[0-9]+]] = or i8 %mcdc.bits, %[[LAB7]]
+// MCDC:  %[[BITS:.+]] = load i8, ptr %[[LAB4]], align 1
+// MCDC:  %[[LAB8:[0-9]+]] = or i8 %[[BITS]], %[[LAB7]]
 // MCDC:  store i8 %[[LAB8]], ptr %[[LAB4]], align 1

diff  --git a/clang/test/Profile/c-mcdc-not.c b/clang/test/Profile/c-mcdc-not.c
index ae683c3fe40fe..7083aa226fb95 100644
--- 

[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/95887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/95887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/95887

>From defd3f6b694a5091da92d925738631b8359c43bb Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 11:10:14 +0900
Subject: [PATCH 1/6] Update ReleaseNotes for MC/DC changes.

---
 clang/docs/ReleaseNotes.rst | 14 ++
 llvm/docs/ReleaseNotes.rst  |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..7ef4fc21c37be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards
+compatible.
+
 Bug Fixes in This Version
 -
 - Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5fdbc9f349af4..555e2632d80a0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@ Changes to the LLVM IR
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
   `_.
+* Semantics of MC/DC intrinsics have been changed.
+  * ``llvm.instprof.mcdc.parameters``: 3rd argument has been changed
+from bytes to bits.
+  * ``llvm.instprof.mcdc.condbitmap.update``: Removed.
+  * ``llvm.instprof.mcdc.tvbitmap.update``: 3rd argument has been
+removed. The next argument has been changed from byte index to bit
+index.
 
 Changes to LLVM infrastructure
 --

>From dc6cd31ef029f0f130a56a39701aa0ee79e6b2c9 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 21:55:20 +0900
Subject: [PATCH 2/6] Reflect feedbacks.

---
 clang/docs/ReleaseNotes.rst | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ef4fc21c37be..0b477dc9f3f2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,19 +586,19 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-Improvements to Coverage mapping
+Improvements to Coverage Mapping
 
 
 - Macros defined in system headers are not expanded in coverage
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
-  with ``-mllvm -system-headers-coverage``. (#78920)
-- MC/DC coverage has been improved. (#82448)
+  with ``-mllvm -system-headers-coverage``.
+  (`#78920: `_)
+- MC/DC Coverage has been improved.
+  (`#82448: `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more details.
-  - The format of profraw generated by the runtime is not backwards
-compatible.
 
 Bug Fixes in This Version
 -

>From 0a537dcc5976b8dc1969d0015645c5e55cb583c7 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 22:02:36 +0900
Subject: [PATCH 3/6] Prune colons

---
 clang/docs/ReleaseNotes.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0b477dc9f3f2a..30b302c2220f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -593,9 +593,9 @@ Improvements to Coverage Mapping
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
   with ``-mllvm -system-headers-coverage``.
-  (`#78920: `_)
+  (`#78920 `_)
 - MC/DC Coverage has been improved.
-  (`#82448: `_)
+  (`#82448 `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more 

[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/95887

>From defd3f6b694a5091da92d925738631b8359c43bb Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 11:10:14 +0900
Subject: [PATCH 1/5] Update ReleaseNotes for MC/DC changes.

---
 clang/docs/ReleaseNotes.rst | 14 ++
 llvm/docs/ReleaseNotes.rst  |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..7ef4fc21c37be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards
+compatible.
+
 Bug Fixes in This Version
 -
 - Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5fdbc9f349af4..555e2632d80a0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@ Changes to the LLVM IR
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
   `_.
+* Semantics of MC/DC intrinsics have been changed.
+  * ``llvm.instprof.mcdc.parameters``: 3rd argument has been changed
+from bytes to bits.
+  * ``llvm.instprof.mcdc.condbitmap.update``: Removed.
+  * ``llvm.instprof.mcdc.tvbitmap.update``: 3rd argument has been
+removed. The next argument has been changed from byte index to bit
+index.
 
 Changes to LLVM infrastructure
 --

>From dc6cd31ef029f0f130a56a39701aa0ee79e6b2c9 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 21:55:20 +0900
Subject: [PATCH 2/5] Reflect feedbacks.

---
 clang/docs/ReleaseNotes.rst | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ef4fc21c37be..0b477dc9f3f2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,19 +586,19 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-Improvements to Coverage mapping
+Improvements to Coverage Mapping
 
 
 - Macros defined in system headers are not expanded in coverage
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
-  with ``-mllvm -system-headers-coverage``. (#78920)
-- MC/DC coverage has been improved. (#82448)
+  with ``-mllvm -system-headers-coverage``.
+  (`#78920: `_)
+- MC/DC Coverage has been improved.
+  (`#82448: `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more details.
-  - The format of profraw generated by the runtime is not backwards
-compatible.
 
 Bug Fixes in This Version
 -

>From 0a537dcc5976b8dc1969d0015645c5e55cb583c7 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 22:02:36 +0900
Subject: [PATCH 3/5] Prune colons

---
 clang/docs/ReleaseNotes.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0b477dc9f3f2a..30b302c2220f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -593,9 +593,9 @@ Improvements to Coverage Mapping
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
   with ``-mllvm -system-headers-coverage``.
-  (`#78920: `_)
+  (`#78920 `_)
 - MC/DC Coverage has been improved.
-  (`#82448: `_)
+  (`#82448 `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more 

[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/95887

>From defd3f6b694a5091da92d925738631b8359c43bb Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 11:10:14 +0900
Subject: [PATCH 1/4] Update ReleaseNotes for MC/DC changes.

---
 clang/docs/ReleaseNotes.rst | 14 ++
 llvm/docs/ReleaseNotes.rst  |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..7ef4fc21c37be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards
+compatible.
+
 Bug Fixes in This Version
 -
 - Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5fdbc9f349af4..555e2632d80a0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@ Changes to the LLVM IR
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
   `_.
+* Semantics of MC/DC intrinsics have been changed.
+  * ``llvm.instprof.mcdc.parameters``: 3rd argument has been changed
+from bytes to bits.
+  * ``llvm.instprof.mcdc.condbitmap.update``: Removed.
+  * ``llvm.instprof.mcdc.tvbitmap.update``: 3rd argument has been
+removed. The next argument has been changed from byte index to bit
+index.
 
 Changes to LLVM infrastructure
 --

>From dc6cd31ef029f0f130a56a39701aa0ee79e6b2c9 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 21:55:20 +0900
Subject: [PATCH 2/4] Reflect feedbacks.

---
 clang/docs/ReleaseNotes.rst | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ef4fc21c37be..0b477dc9f3f2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,19 +586,19 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-Improvements to Coverage mapping
+Improvements to Coverage Mapping
 
 
 - Macros defined in system headers are not expanded in coverage
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
-  with ``-mllvm -system-headers-coverage``. (#78920)
-- MC/DC coverage has been improved. (#82448)
+  with ``-mllvm -system-headers-coverage``.
+  (`#78920: `_)
+- MC/DC Coverage has been improved.
+  (`#82448: `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more details.
-  - The format of profraw generated by the runtime is not backwards
-compatible.
 
 Bug Fixes in This Version
 -

>From 0a537dcc5976b8dc1969d0015645c5e55cb583c7 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 22:02:36 +0900
Subject: [PATCH 3/4] Prune colons

---
 clang/docs/ReleaseNotes.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0b477dc9f3f2a..30b302c2220f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -593,9 +593,9 @@ Improvements to Coverage Mapping
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
   with ``-mllvm -system-headers-coverage``.
-  (`#78920: `_)
+  (`#78920 `_)
 - MC/DC Coverage has been improved.
-  (`#82448: `_)
+  (`#82448 `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more 

[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/95887

>From defd3f6b694a5091da92d925738631b8359c43bb Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 11:10:14 +0900
Subject: [PATCH 1/2] Update ReleaseNotes for MC/DC changes.

---
 clang/docs/ReleaseNotes.rst | 14 ++
 llvm/docs/ReleaseNotes.rst  |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..7ef4fc21c37be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards
+compatible.
+
 Bug Fixes in This Version
 -
 - Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5fdbc9f349af4..555e2632d80a0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@ Changes to the LLVM IR
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
   `_.
+* Semantics of MC/DC intrinsics have been changed.
+  * ``llvm.instprof.mcdc.parameters``: 3rd argument has been changed
+from bytes to bits.
+  * ``llvm.instprof.mcdc.condbitmap.update``: Removed.
+  * ``llvm.instprof.mcdc.tvbitmap.update``: 3rd argument has been
+removed. The next argument has been changed from byte index to bit
+index.
 
 Changes to LLVM infrastructure
 --

>From dc6cd31ef029f0f130a56a39701aa0ee79e6b2c9 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 21:55:20 +0900
Subject: [PATCH 2/2] Reflect feedbacks.

---
 clang/docs/ReleaseNotes.rst | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ef4fc21c37be..0b477dc9f3f2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,19 +586,19 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-Improvements to Coverage mapping
+Improvements to Coverage Mapping
 
 
 - Macros defined in system headers are not expanded in coverage
   mapping. Conditional expressions in system header macros are no
   longer taken into account for branch coverage. They can be included
-  with ``-mllvm -system-headers-coverage``. (#78920)
-- MC/DC coverage has been improved. (#82448)
+  with ``-mllvm -system-headers-coverage``.
+  (`#78920: `_)
+- MC/DC Coverage has been improved.
+  (`#82448: `_)
   - The maximum number of conditions is no longer limited to 6. See
 `this ` for
 more details.
-  - The format of profraw generated by the runtime is not backwards
-compatible.
 
 Bug Fixes in This Version
 -

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits


@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards

chapuni wrote:

It'd be appropriate to drop mentioning backward compatibility here, since it is 
our common sense.

I wanted to mention incompatibility of data semantics. Apparently, only 
`llvm-cov` would be affected.


https://github.com/llvm/llvm-project/pull/95887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

I've created #95887 (Release notes).

https://github.com/llvm/llvm-project/pull/95496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Update ReleaseNotes for MC/DC changes. (PR #95887)

2024-06-18 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/95887

Mostly apparent changes are described here.

>From defd3f6b694a5091da92d925738631b8359c43bb Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Tue, 18 Jun 2024 11:10:14 +0900
Subject: [PATCH] Update ReleaseNotes for MC/DC changes.

---
 clang/docs/ReleaseNotes.rst | 14 ++
 llvm/docs/ReleaseNotes.rst  |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36efeb8c70cca..7ef4fc21c37be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -586,6 +586,20 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+Improvements to Coverage mapping
+
+
+- Macros defined in system headers are not expanded in coverage
+  mapping. Conditional expressions in system header macros are no
+  longer taken into account for branch coverage. They can be included
+  with ``-mllvm -system-headers-coverage``. (#78920)
+- MC/DC coverage has been improved. (#82448)
+  - The maximum number of conditions is no longer limited to 6. See
+`this ` for
+more details.
+  - The format of profraw generated by the runtime is not backwards
+compatible.
+
 Bug Fixes in This Version
 -
 - Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5fdbc9f349af4..555e2632d80a0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@ Changes to the LLVM IR
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
   `_.
+* Semantics of MC/DC intrinsics have been changed.
+  * ``llvm.instprof.mcdc.parameters``: 3rd argument has been changed
+from bytes to bits.
+  * ``llvm.instprof.mcdc.condbitmap.update``: Removed.
+  * ``llvm.instprof.mcdc.tvbitmap.update``: 3rd argument has been
+removed. The next argument has been changed from byte index to bit
+index.
 
 Changes to LLVM infrastructure
 --

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@zmodem #82448 doesn't use intermediate condbitmap but integer index. I decided 
not to modify and use the intrinsic `condbitmapupdate`, since the signature 
will be quite different and this is too simple to be put into the intrinsic.
Also pre-#82448 impl of `condbitmapupdate` was so simple (`|= (V << ID)`) just 
to update the local variable. I wondered why it was implemented with the 
intrinsic.

In contrast, I modified `tvbitmapupdate` in #82448 without getting rid of it. I 
modified its signature and semantics. I thought `tvbitmapupdate` might be left 
as an intrinsic since it could be enhanced to atomic ops (and continuous bias 
mode).

I guess they would hit apparently buggy behavior if they were using obsolete 
`condbitmapupdate` and modified `tvbitmapupdate`.

Since I didn't update and won't update the semantics of `condupdate`, they 
should get rid of it, as far as they follow our trunk. I don't think I could 
provide "easy" migration path.

https://github.com/llvm/llvm-project/pull/95496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@zmodem Thanks for the notification.
I supposed release notes may be updated just before the release. I was 
wondering how I could propagate changes.
I will fill recent changes to Release notes, later.

Re. condbitmap.update, it has become useless after #82448 . I think pruning it 
will be the possible way.

https://github.com/llvm/llvm-project/pull/95496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-15 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/95496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-14 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

Oh, it's apple-specific continuous mode test :(

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 43bd7ae - StreamChecker.cpp: Use isa<> (for #93408) [-Wunused-but-set-variable]

2024-06-13 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-06-14T12:18:41+09:00
New Revision: 43bd7ae65af40ff3378d5a0395a058ba834ad8dd

URL: 
https://github.com/llvm/llvm-project/commit/43bd7ae65af40ff3378d5a0395a058ba834ad8dd
DIFF: 
https://github.com/llvm/llvm-project/commit/43bd7ae65af40ff3378d5a0395a058ba834ad8dd.diff

LOG: StreamChecker.cpp: Use isa<> (for #93408) [-Wunused-but-set-variable]

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 74ee607849a5b..613c221de7b4c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -969,9 +969,9 @@ static std::optional getStartIndex(SValBuilder ,
 
   if (const auto *ER = dyn_cast(R))
 return ER->getIndex();
-  if (const auto *TR = dyn_cast(R))
+  if (isa(R))
 return Zero();
-  if (const auto *SR = dyn_cast(R))
+  if (isa(R))
 return Zero();
   return std::nullopt;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/95496

3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg.

Sweep `condbitmap.update`, since it is no longer used.

>From 80e4ff0501e6ba4c30bd94faec03ba3dcd2ad4ee Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Thu, 13 Jun 2024 20:28:22 +0900
Subject: [PATCH] Cleanup MC/DC intrinsics for #82448

3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg.

Sweep `condbitmap.update`, since it is no longer used.
---
 clang/lib/CodeGen/CodeGenPGO.cpp  |  3 +-
 clang/test/Profile/c-mcdc.c   |  2 +-
 llvm/docs/LangRef.rst | 53 +--
 llvm/include/llvm/IR/IntrinsicInst.h  | 35 +---
 llvm/include/llvm/IR/Intrinsics.td|  7 +--
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  2 -
 .../Instrumentation/InstrProfiling.cpp| 35 
 .../Instrumentation/InstrProfiling/mcdc.ll| 13 +
 llvm/unittests/IR/IntrinsicsTest.cpp  |  3 --
 9 files changed, 9 insertions(+), 144 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 59139e342de88..2839697614595 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1260,9 +1260,8 @@ void 
CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy ,
   // from a pointer to a dedicated temporary value on the stack that is itself
   // updated via emitMCDCCondBitmapReset() and emitMCDCCondBitmapUpdate(). The
   // index represents an executed test vector.
-  llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
+  llvm::Value *Args[4] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
   Builder.getInt64(FunctionHash),
-  Builder.getInt32(0), // Unused
   Builder.getInt32(MCDCTestVectorBitmapOffset),
   MCDCCondBitmapAddr.emitRawPointer(CGF)};
   Builder.CreateCall(
diff --git a/clang/test/Profile/c-mcdc.c b/clang/test/Profile/c-mcdc.c
index 251c18baa861d..7c1d734028364 100644
--- a/clang/test/Profile/c-mcdc.c
+++ b/clang/test/Profile/c-mcdc.c
@@ -82,7 +82,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 
 // UPDATE FINAL BITMASK WITH RESULT.
 // NOPROFPASS-LABEL: lor.end:
-// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr 
@__profn_test, i64 [[HASH]], i32 0, i32 0, ptr %mcdc.addr)
+// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr 
@__profn_test, i64 [[HASH]], i32 0, ptr %mcdc.addr)
 // MCDC-DAG:  %[[TEMP0:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDC:  %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0
 // MCDC:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 10d53bea149ef..a587afed6ca88 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14441,52 +14441,6 @@ to generate the appropriate data structures and the 
code to instrument MC/DC
 test vectors in a format that can be written out by a compiler runtime and
 consumed via the ``llvm-profdata`` tool.
 
-'``llvm.instrprof.mcdc.condbitmap.update``' Intrinsic
-^
-
-Syntax:
-"""
-
-::
-
-  declare void @llvm.instrprof.mcdc.condbitmap.update(ptr , i64 
,
-  i32 ,
-  ptr ,
-  i1 )
-
-Overview:
-"
-
-The '``llvm.instrprof.mcdc.condbitmap.update``' intrinsic is used to track
-MC/DC condition evaluation for each condition in a boolean expression.
-
-Arguments:
-""
-
-The first argument is a pointer to a global variable containing the
-name of the entity being instrumented. This should generally be the
-(mangled) function name for a set of counters.
-
-The second argument is a hash value that can be used by the consumer
-of the profile data to detect changes to the instrumented source.
-
-The third argument is an ID of a condition to track. This value is used as a
-bit index into the condition bitmap.
-
-The fourth argument is the address of the condition bitmap.
-
-The fifth argument is the boolean value representing the evaluation of the
-condition (true or false)
-
-Semantics:
-""
-
-This intrinsic represents the update of a condition bitmap that is local to a
-function and will cause the ``-instrprof`` pass to generate the code to
-instrument the control flow around each condition in a boolean expression. The
-ID of each condition corresponds to a bit index in the condition bitmap which
-is set based on the evaluation of the condition.
-
 '``llvm.instrprof.mcdc.tvbitmap.update``' Intrinsic
 ^^^
 
@@ -14496,7 +14450,6 @@ Syntax:
 ::
 
   declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr , i64 ,
-

[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits


@@ -2122,20 +2135,70 @@ struct CounterCoverageMappingBuilder
  subtractCounters(ParentCount, TrueCount));
   }
 
-  void createDecision(const BinaryOperator *E) {
+  void createOrCancelDecision(const BinaryOperator *E, unsigned Since) {
 unsigned NumConds = MCDCBuilder.getTotalConditionsAndReset(E);
 if (NumConds == 0)
   return;
 
+// Extract [ID, Conds] to construct the graph.
+llvm::SmallVector CondIDs(NumConds);
+for (const auto  : ArrayRef(SourceRegions).slice(Since)) {
+  if (SR.isMCDCBranch()) {
+auto [ID, Conds] = SR.getMCDCBranchParams();
+CondIDs[ID] = Conds;
+  }
+}
+
+// Construct the graph and calculate `Indices`.
+mcdc::TVIdxBuilder Builder(CondIDs);
+unsigned NumTVs = Builder.NumTestVectors;
+unsigned MaxTVs = CVM.getCodeGenModule().getCodeGenOpts().MCDCMaxTVs;
+assert(MaxTVs < mcdc::TVIdxBuilder::HardMaxTVs);

chapuni wrote:

`HardMaxTVs(int_max)` is actually the error code.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8b435c1 - ASTTests: Suppress a warning in -Asserts for #95202 [-Wunused-variable]

2024-06-13 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-06-13T17:34:39+09:00
New Revision: 8b435c18314e62530367a8721883a28c532e02ad

URL: 
https://github.com/llvm/llvm-project/commit/8b435c18314e62530367a8721883a28c532e02ad
DIFF: 
https://github.com/llvm/llvm-project/commit/8b435c18314e62530367a8721883a28c532e02ad.diff

LOG: ASTTests: Suppress a warning in -Asserts for #95202 [-Wunused-variable]

Added: 


Modified: 
clang/unittests/AST/ProfilingTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ProfilingTest.cpp 
b/clang/unittests/AST/ProfilingTest.cpp
index ed81f4e1c5f2f..27a4a197f1cbf 100644
--- a/clang/unittests/AST/ProfilingTest.cpp
+++ b/clang/unittests/AST/ProfilingTest.cpp
@@ -34,8 +34,10 @@ static auto getClassTemplateRedecls() {
   Res.push_back(CTD);
   }
   assert(Res.size() == 3);
+#ifndef NDEBUG
   for (auto & : Res)
 assert(I->getCanonicalDecl() == Res[0]);
+#endif
   return std::make_tuple(std::move(AST), Res[1], Res[2]);
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits


@@ -484,10 +484,31 @@ MC/DC Instrumentation
 -
 
 When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
-clang option ``-fcoverage-mcdc``, users are limited to at most **six** 
leaf-level
-conditions in a boolean expression.  A warning will be generated for boolean
-expressions that contain more than six, and they will not be instrumented for
-MC/DC.
+clang option ``-fcoverage-mcdc``, there are two hard limits.
+
+The maximum number of terms is limited to 32767, which is practical for
+handwritten expressions. To be more restrictive in order to enforce coding 
rules,
+use ``-Xclang -fmcdc-max-conditions=n``. Expressions with exceeded condition
+counts ``n`` will generate warnings.

chapuni wrote:

Done.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits


@@ -14416,7 +14416,7 @@ Syntax:
 ::
 
   declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr , i64 ,
-i32 )
+i32 )

chapuni wrote:

I wanted to leave the signature of instrinsics as-is. I will remove it in the 
next request.
(FYI, condupdate is not used)

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix broken canonicalization of DeducedTemplateSpecializationType (PR #95202)

2024-06-13 Thread NAKAMURA Takumi via cfe-commits


@@ -0,0 +1,73 @@
+//===- unittests/AST/ProfilingTest.cpp --- Tests for Profiling --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace {
+using namespace ast_matchers;
+
+static auto getClassTemplateRedecls() {
+  std::string Code = R"cpp(
+template  struct A;
+template  struct A;
+template  struct A;
+  )cpp";
+  auto AST = tooling::buildASTFromCode(Code);
+  ASTContext  = AST->getASTContext();
+
+  auto MatchResults = match(classTemplateDecl().bind("id"), Ctx);
+  SmallVector Res;
+  for (BoundNodes  : MatchResults) {
+if (auto *CTD = const_cast(
+N.getNodeAs("id")))
+  Res.push_back(CTD);
+  }
+  assert(Res.size() == 3);
+  for (auto & : Res)

chapuni wrote:

`I` is used only for +Asserts.

https://github.com/llvm/llvm-project/pull/95202
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-11 Thread NAKAMURA Takumi via cfe-commits


@@ -484,10 +484,31 @@ MC/DC Instrumentation
 -
 
 When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
-clang option ``-fcoverage-mcdc``, users are limited to at most **six** 
leaf-level
-conditions in a boolean expression.  A warning will be generated for boolean
-expressions that contain more than six, and they will not be instrumented for
-MC/DC.
+clang option ``-fcoverage-mcdc``, there are two hard limits.
+
+The maximum number of terms is limited to 32767, which is practical for
+handwritten expressions. To be more restrictive in order to enforce coding 
rules,
+use ``-Xclang -fmcdc-max-conditions=n``. Expressions with exceeded condition
+counts ``n`` will generate warnings.
+
+The number of test vectors (the maximum number of possible combinations of
+expressions) is limited to 2,147,483,646. In this case, approximately
+256MiB (==2GiB/8) is used to record test vectors.
+
+To reduce memory usage, you can limit the maximum number of test vectors per

chapuni wrote:

Done -- s/you/users/

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits


@@ -484,10 +484,31 @@ MC/DC Instrumentation
 -
 
 When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
-clang option ``-fcoverage-mcdc``, users are limited to at most **six** 
leaf-level
-conditions in a boolean expression.  A warning will be generated for boolean
-expressions that contain more than six, and they will not be instrumented for
-MC/DC.
+clang option ``-fcoverage-mcdc``, there are two hard limits.

chapuni wrote:

Do you suggest replacing "there are two hard limits" with the explanation of 
`max-conditions=32767`?

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits


@@ -484,10 +484,31 @@ MC/DC Instrumentation
 -
 
 When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
-clang option ``-fcoverage-mcdc``, users are limited to at most **six** 
leaf-level
-conditions in a boolean expression.  A warning will be generated for boolean
-expressions that contain more than six, and they will not be instrumented for
-MC/DC.
+clang option ``-fcoverage-mcdc``, there are two hard limits.
+
+The maximum number of terms is limited to 32767, which is practical for
+handwritten expressions. To be more restrictive in order to enforce coding 
rules,
+use ``-Xclang -fmcdc-max-conditions=n``. Expressions with exceeded condition
+counts ``n`` will generate warnings.
+
+The number of test vectors (the maximum number of possible combinations of
+expressions) is limited to 2,147,483,646. In this case, approximately
+256MiB (==2GiB/8) is used to record test vectors.
+
+To reduce memory usage, you can limit the maximum number of test vectors per

chapuni wrote:

Oh I didn't type "you" at first. Re-translation transformed the sentence.
Maybe "users" here, rather than transforming to passive sentence?

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits


@@ -484,10 +484,31 @@ MC/DC Instrumentation
 -
 
 When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
-clang option ``-fcoverage-mcdc``, users are limited to at most **six** 
leaf-level
-conditions in a boolean expression.  A warning will be generated for boolean
-expressions that contain more than six, and they will not be instrumented for
-MC/DC.
+clang option ``-fcoverage-mcdc``, there are two hard limits.
+
+The maximum number of terms is limited to 32767. It would be practical for
+handwritten expressions. To be more retrictive in order to enfoce conding 
rules,

chapuni wrote:

Done (and revised a little). Thanks!

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

I am certain this is ready for land.

Could I update release notes later? I am afraid since I have been always 
missing release schedules.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix the warning in RefCntblBaseVirtualDtorChecker.cpp:61 (PR #93403)

2024-05-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni approved this pull request.

Thanks!

https://github.com/llvm/llvm-project/pull/93403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-25 Thread NAKAMURA Takumi via cfe-commits


@@ -11,16 +11,116 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefFuncDeleteExprVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefFuncDeleteExprVisitor(const TemplateArgumentList ,
+ const CXXRecordDecl *ClassDecl)
+  : ArgList(), ClassDecl(ClassDecl) {}
+
+  DerefFuncDeleteExprVisitor(const CXXRecordDecl *ClassDecl)
+  : ClassDecl(ClassDecl) {}
+
+  std::optional HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Body = Decl->getBody())
+  return VisitBody(Body);
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())

chapuni wrote:

This causes a warning.

```
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp:61:15:
 warning: variable 'Tmpl' set but not used [-Wunused-but-set-variable]
```

https://github.com/llvm/llvm-project/pull/92837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-23 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@whentojump AFAIK, both of them missed boarding 18.1.6. I'll wait for 
opportunities.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-23 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-23 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni approved this pull request.

I'd like other approvals by clang guys. @AaronBallman Could you nominate anyone?

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-23 Thread NAKAMURA Takumi via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s

chapuni wrote:

You may overwrite 896bceb with this.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-05-22 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/89572
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-05-22 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/89572
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-22 Thread NAKAMURA Takumi via cfe-commits


@@ -339,8 +365,18 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Region with its definition if it is in .
+  auto NonScratchExpansionLoc = getNonScratchExpansionLoc(Loc);
+  Loc = NonScratchExpansionLoc.first;

chapuni wrote:

I think updating Loc should be sunk into `then` clause explicitly, even if Loc 
is immutable when !EndLoc.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-22 Thread NAKAMURA Takumi via cfe-commits


@@ -292,10 +292,36 @@ class CoverageMappingBuilder {
 return SM.getLocForEndOfFile(SM.getFileID(Loc));
   }
 
-  /// Find out where the current file is included or macro is expanded.
-  SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc) {
-return Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getBegin()
-   : SM.getIncludeLoc(SM.getFileID(Loc));
+  /// Find out where a macro is expanded. If the immediate result is a
+  /// , keep looking until the result isn't. Return the source
+  /// range of the found result, or std::nullopt if the while loop didn't get
+  /// executed, which means the location wasn't changed.
+  std::optional getNonScratchExpansion(SourceLocation Loc) {
+std::optional EndLoc = std::nullopt;
+while (Loc.isMacroID() &&
+   SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
+  auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
+  Loc = ExpansionRange.getBegin();
+  EndLoc = ExpansionRange.getEnd();
+}
+if (EndLoc.has_value())
+  return SourceRange(Loc, EndLoc.value());

chapuni wrote:

I meant;
```
  auto getNonScratchExpansionLoc(SourceLocation Loc) {
std::optional ExpansionRange = std::nullopt;
while (Loc.isMacroID() &&
   SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
  ExpansionRange = SM.getImmediateExpansionRange(Loc);
  Loc = ExpansionRange->getBegin();
}
return ExpansionRange;
  }
```
(No need to follow)

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-22 Thread NAKAMURA Takumi via cfe-commits


@@ -339,8 +365,18 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Region with its definition if it is in .

chapuni wrote:

Now this collides to #91446 . Could you update?
I suggest this may come in advance of #91446.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-05-21 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@whentojump Any updates? Or Is it better for me to take this over?

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Rework !SystemHeadersCoverage (PR #91446)

2024-05-20 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@AaronBallman Thanks. Aha, I've noticed my test was incompatible for targeting 
msvc mangling.

https://github.com/llvm/llvm-project/pull/91446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-05-20 Thread NAKAMURA Takumi via cfe-commits


@@ -190,6 +190,16 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {

chapuni wrote:

Removed. (It is in another request)

https://github.com/llvm/llvm-project/pull/89572
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-05-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/89572

>From 13035b230fd51422f6c3223fcffab4f44bd00956 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 19 Apr 2024 15:26:34 +0900
Subject: [PATCH 1/4] [MC/DC][Coverage] Add assertions into emitSourceRegions()

`emitSourceRegions()` has bugs to emit malformed MC/DC coverage mappings.
They were detected in `llvm-cov` as the crash.

Detect inconsistencies earlier in `clang` with assertions.

* mcdc-system-headers.cpp covers #78920.
* mcdc-scratch-space.c covers #87000.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 29 ++--
 .../test/CoverageMapping/mcdc-scratch-space.c | 27 +++
 .../CoverageMapping/mcdc-system-headers.cpp   | 47 +++
 3 files changed, 98 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-scratch-space.c
 create mode 100644 clang/test/CoverageMapping/mcdc-system-headers.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d..95ad1967c8b67 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -190,11 +190,21 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {
+return mcdc::getParams(MCDCParams);
+  }
+
   bool isMCDCDecision() const {
 const auto *DecisionParams =
 std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+assert(DecisionParams == nullptr || DecisionParams->NumConditions > 0);
+return (DecisionParams != nullptr);
   }
 
   const auto () const {
@@ -464,13 +474,19 @@ class CoverageMappingBuilder {
   // Ignore regions from system headers unless collecting coverage from
   // system headers is explicitly enabled.
   if (!SystemHeadersCoverage &&
-  SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
+  SM.isInSystemHeader(SM.getSpellingLoc(LocStart))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in system headers");
 continue;
+  }
 
   auto CovFileID = getCoverageFileID(LocStart);
   // Ignore regions that don't have a file, such as builtin macros.
-  if (!CovFileID)
+  if (!CovFileID) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in non-file regions");
 continue;
+  }
 
   SourceLocation LocEnd = Region.getEndLoc();
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
@@ -480,8 +496,11 @@ class CoverageMappingBuilder {
   // This not only suppresses redundant regions, but sometimes prevents
   // creating regions with wrong counters if, for example, a statement's
   // body ends at the end of a nested macro.
-  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+  if (Filter.count(std::make_pair(LocStart, LocEnd))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition");
 continue;
+  }
 
   // Find the spelling locations for the mapping region.
   SpellingRegion SR{SM, LocStart, LocEnd};
diff --git a/clang/test/CoverageMapping/mcdc-scratch-space.c 
b/clang/test/CoverageMapping/mcdc-scratch-space.c
new file mode 100644
index 0..962d10653a028
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-scratch-space.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s
+// XFAIL: *
+// REQUIRES: asserts
+
+int builtin_macro0(int a) {
+  return (__LINE__
+  && a);
+}
+
+int builtin_macro1(int a) {
+  return (a
+  || __LINE__);
+}
+
+#define PRE(x) pre_##x
+
+int pre0(int pre_a, int b_post) {
+  return (PRE(a)
+  && b_post);
+}
+
+#define POST(x) x##_post
+
+int post0(int pre_a, int b_post) {
+  return (pre_a
+  || POST(b));
+}
diff --git a/clang/test/CoverageMapping/mcdc-system-headers.cpp 
b/clang/test/CoverageMapping/mcdc-system-headers.cpp
new file mode 100644
index 0..329bb37822a9e
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-system-headers.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping  -fcoverage-mcdc -mllvm -system-headers-coverage 
-emit-llvm-only -o - %s | FileCheck %s
+
+// Will crash w/o -system-headers-coverage
+// RUN: not --crash %clang_cc1 -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -fcoverage-mcdc -emit-llvm-only -o - 
%s
+// REQUIRES: asserts
+
+#ifdef 

[clang] [Coverage] Rework !SystemHeadersCoverage (PR #91446)

2024-05-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/91446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Rework !SystemHeadersCoverage (PR #91446)

2024-05-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/91446

>From d3ee2d086d07ce0803117ec9fa16ac72801619c7 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Thu, 2 May 2024 09:36:39 +0900
Subject: [PATCH 1/2] [Coverage] Rework !SystemHeadersCoverage

- Introduce `LeafExprSet`,
  - Suppress traversing LAnd and LOr expr under system headers.
  - Handle LAnd and LOr as instrumented leaves to override
`!isInstrumentedCondition(C)`.
- Replace Loc with FileLoc if it is expanded with system headers.

Fixes #78920
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 48 +++---
 .../CoverageMapping/mcdc-system-headers.cpp   | 50 +++
 2 files changed, 92 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-system-headers.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d..15d7199e95b0f 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
@@ -339,16 +340,26 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Loc with FileLoc if it is expanded with system headers.
+  if (!SystemHeadersCoverage && SM.isInSystemMacro(Loc)) {
+auto BeginLoc = SM.getSpellingLoc(Loc);
+auto EndLoc = SM.getSpellingLoc(Region.getEndLoc());
+if (SM.isWrittenInSameFile(BeginLoc, EndLoc)) {
+  Loc = SM.getFileLoc(Loc);
+  Region.setStartLoc(Loc);
+  Region.setEndLoc(SM.getFileLoc(Region.getEndLoc()));
+}
+  }
+
   FileID File = SM.getFileID(Loc);
   if (!Visited.insert(File).second)
 continue;
 
-  // Do not map FileID's associated with system headers unless collecting
-  // coverage from system headers is explicitly enabled.
-  if (!SystemHeadersCoverage && 
SM.isInSystemHeader(SM.getSpellingLoc(Loc)))
-continue;
+  assert(SystemHeadersCoverage ||
+ !SM.isInSystemHeader(SM.getSpellingLoc(Loc)));
 
   unsigned Depth = 0;
   for (SourceLocation Parent = getIncludeOrExpansionLoc(Loc);
@@ -821,6 +832,10 @@ struct CounterCoverageMappingBuilder
   /// A stack of currently live regions.
   llvm::SmallVector RegionStack;
 
+  /// Set if the Expr should be handled as a leaf even if it is kind of binary
+  /// logical ops (&&, ||).
+  llvm::DenseSet LeafExprSet;
+
   /// An object to manage MCDC regions.
   MCDCCoverageBuilder MCDCBuilder;
 
@@ -1043,7 +1058,10 @@ struct CounterCoverageMappingBuilder
 // region onto RegionStack but immediately pop it (which adds it to the
 // function's SourceRegions) because it doesn't apply to any other source
 // code other than the Condition.
-if (CodeGenFunction::isInstrumentedCondition(C)) {
+// With !SystemHeadersCoverage, binary logical ops in system headers may be
+// treated as instrumentable conditions.
+if (CodeGenFunction::isInstrumentedCondition(C) ||
+LeafExprSet.count(CodeGenFunction::stripCond(C))) {
   mcdc::Parameters BranchParams;
   mcdc::ConditionID ID = MCDCBuilder.getCondID(C);
   if (ID >= 0)
@@ -2064,7 +2082,20 @@ struct CounterCoverageMappingBuilder
 createDecisionRegion(E, DecisionParams);
   }
 
+  /// Check if E belongs to system headers.
+  bool isExprInSystemHeader(const BinaryOperator *E) const {
+return (!SystemHeadersCoverage &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getOperatorLoc())) &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getBeginLoc())) &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getEndLoc(;
+  }
+
   void VisitBinLAnd(const BinaryOperator *E) {
+if (isExprInSystemHeader(E)) {
+  LeafExprSet.insert(E);
+  return;
+}
+
 bool IsRootNode = MCDCBuilder.isIdle();
 
 // Keep track of Binary Operator and assign MCDC condition IDs.
@@ -2119,6 +2150,11 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitBinLOr(const BinaryOperator *E) {
+if (isExprInSystemHeader(E)) {
+  LeafExprSet.insert(E);
+  return;
+}
+
 bool IsRootNode = MCDCBuilder.isIdle();
 
 // Keep track of Binary Operator and assign MCDC condition IDs.
diff --git a/clang/test/CoverageMapping/mcdc-system-headers.cpp 
b/clang/test/CoverageMapping/mcdc-system-headers.cpp
new file mode 100644
index 0..829b8170fc62a
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-system-headers.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang 

[clang] [Coverage] Rework !SystemHeadersCoverage (PR #91446)

2024-05-19 Thread NAKAMURA Takumi via cfe-commits


@@ -2064,7 +2082,20 @@ struct CounterCoverageMappingBuilder
 createDecisionRegion(E, DecisionParams);
   }
 
+  /// Check if E belongs to system headers.
+  bool isExprInSystemHeader(const BinaryOperator *E) const {

chapuni wrote:

I assume each visitor (`visitBinLAnd` `visitBinLOr`) will not receive nullptr.

https://github.com/llvm/llvm-project/pull/91446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-16 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

For now, I've implemented almost functionalities for this.

Both `-fmcdc-max-conditions=32767` and `-fmcdc-max-test-vectors=0x7FFE` are 
cc1options.

`llvm-cov` can understand `clang-18`'s profdata (and objects).

TODO: documents and test cases

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-16 Thread NAKAMURA Takumi via cfe-commits


@@ -983,7 +979,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
   // for most embedded applications. Setting a maximum value prevents the
   // bitmap footprint from growing too large without the user's knowledge. In
   // the future, this value could be adjusted with a command-line option.
-  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 6 : 0;
+  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 32767 : 0;

chapuni wrote:

@evodius96 I've introduced `-fmcdc-max-conditions=32767`.
> against unintended memory footprint expansion
I think `-fmcdc-max-test-vectors=64` can restrict max bitmap size as the 
current implementation.

@ornata I have no idea how to determine practical limit for that. So I use 
`SHRT_MAX`.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-10 Thread NAKAMURA Takumi via cfe-commits


@@ -190,18 +190,30 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {
+return mcdc::getParams(MCDCParams);
+  }
+
   bool isMCDCDecision() const {
 const auto *DecisionParams =
 std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+assert(DecisionParams == nullptr || DecisionParams->NumConditions > 0);

chapuni wrote:

I committed 2a61eebc66c0903cf3834a520b1f975ac3cdf92b as well.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2a61eeb - Cleanup asserts in BranchParameters and DecisionParameters

2024-05-10 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-05-10T16:00:16+09:00
New Revision: 2a61eebc66c0903cf3834a520b1f975ac3cdf92b

URL: 
https://github.com/llvm/llvm-project/commit/2a61eebc66c0903cf3834a520b1f975ac3cdf92b
DIFF: 
https://github.com/llvm/llvm-project/commit/2a61eebc66c0903cf3834a520b1f975ac3cdf92b.diff

LOG: Cleanup asserts in BranchParameters and DecisionParameters

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 733686d4946b3..ce2f39aeb0821 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -191,10 +191,7 @@ class SourceMappingRegion {
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const {
-const auto *DecisionParams =
-std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+return std::holds_alternative(MCDCParams);
   }
 
   const auto () const {

diff  --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 7a8b6639f2971..da03104045249 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -462,10 +462,7 @@ struct MCDCRecord {
 
   CounterMappingRegion getDecisionRegion() const { return Region; }
   unsigned getNumConditions() const {
-unsigned NumConditions = Region.getDecisionParams().NumConditions;
-assert(NumConditions != 0 &&
-   "In MC/DC, NumConditions should never be zero!");
-return NumConditions;
+return Region.getDecisionParams().NumConditions;
   }
   unsigned getNumTestVectors() const { return TV.size(); }
   bool isCondFolded(unsigned Condition) const { return Folded[Condition]; }

diff  --git a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h 
b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
index 8c78bed4dec52..191e4ead95ea2 100644
--- a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
+++ b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
@@ -33,7 +33,9 @@ struct DecisionParameters {
 
   DecisionParameters() = delete;
   DecisionParameters(unsigned BitmapIdx, unsigned NumConditions)
-  : BitmapIdx(BitmapIdx), NumConditions(NumConditions) {}
+  : BitmapIdx(BitmapIdx), NumConditions(NumConditions) {
+assert(NumConditions > 0);
+  }
 };
 
 struct BranchParameters {
@@ -44,7 +46,9 @@ struct BranchParameters {
 
   BranchParameters() = delete;
   BranchParameters(ConditionID ID, const ConditionIDs )
-  : ID(ID), Conds(Conds) {}
+  : ID(ID), Conds(Conds) {
+assert(ID >= 0);
+  }
 };
 
 /// The type of MC/DC-specific parameters.

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 6c77ce017c036..8c81bbe8e9c4e 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -338,7 +338,6 @@ class NextIDsBuilder {
 #endif
 for (const auto *Branch : Branches) {
   const auto  = Branch->getBranchParams();
-  assert(BranchParams.ID >= 0 && "CondID isn't set");
   assert(SeenIDs.insert(BranchParams.ID).second && "Duplicate CondID");
   NextIDs[BranchParams.ID] = BranchParams.Conds;
 }
@@ -694,7 +693,6 @@ class MCDCDecisionRecorder {
   assert(Branch.Kind == CounterMappingRegion::MCDCBranchRegion);
 
   auto ConditionID = Branch.getBranchParams().ID;
-  assert(ConditionID >= 0 && "ConditionID should be positive");
 
   if (ConditionIDs.contains(ConditionID) ||
   ConditionID >= DecisionParams.NumConditions)

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
index 5036bde5aca72..adfd22804356e 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -256,7 +256,6 @@ void CoverageMappingWriter::write(raw_ostream ) {
 // They are written as internal values plus 1.
 const auto  = I->getBranchParams();
 ParamsShouldBeNull = false;
-assert(BranchParams.ID >= 0);
 unsigned ID1 = BranchParams.ID + 1;
 unsigned TID1 = BranchParams.Conds[true] + 1;
 unsigned FID1 = BranchParams.Conds[false] + 1;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7e52ad3 - Fix a warning for #91455 [-Wc++20-extensions]

2024-05-10 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-05-10T16:00:16+09:00
New Revision: 7e52ad3b5b9509d0873965e8492ab01141342822

URL: 
https://github.com/llvm/llvm-project/commit/7e52ad3b5b9509d0873965e8492ab01141342822
DIFF: 
https://github.com/llvm/llvm-project/commit/7e52ad3b5b9509d0873965e8492ab01141342822.diff

LOG: Fix a warning for #91455 [-Wc++20-extensions]

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp
index 0a2514a2d7c12..d194742dbea7d 100644
--- a/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp
@@ -20,7 +20,7 @@ 
SolverTest::createSolverWithLowTimeout() {
 namespace {
 
 INSTANTIATE_TYPED_TEST_SUITE_P(WatchedLiteralsSolverTest, SolverTest,
-   WatchedLiteralsSolver);
+   WatchedLiteralsSolver, );
 
 } // namespace
 } // namespace clang::dataflow::test



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-10 Thread NAKAMURA Takumi via cfe-commits


@@ -190,18 +190,30 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);

chapuni wrote:

I've removed the assertion. (I will commit other changes in BranchParams and 
DecisionParams later)

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-10 Thread NAKAMURA Takumi via cfe-commits


@@ -1128,9 +1122,11 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy 
) {
   // Emit intrinsic representing MCDC bitmap parameters at function entry.
   // This is used by the instrumentation pass, but it isn't actually lowered to
   // anything.
-  llvm::Value *Args[3] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
-  Builder.getInt64(FunctionHash),
-  Builder.getInt32(RegionMCDCState->BitmapBytes)};
+  llvm::Value *Args[3] = {
+  llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
+  Builder.getInt64(FunctionHash),
+  Builder.getInt32(llvm::alignTo(RegionMCDCState->BitmapBits, CHAR_BIT) /
+   CHAR_BIT)};

chapuni wrote:

Modified 3rd arg of `mcdc.parameters` as bitcnt.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-05-09 Thread NAKAMURA Takumi via cfe-commits


@@ -2050,23 +2069,74 @@ struct CounterCoverageMappingBuilder
  subtractCounters(ParentCount, TrueCount));
   }
 
-  void createDecision(const BinaryOperator *E) {
+  void createOrCancelDecision(const BinaryOperator *E, unsigned Since) {
 unsigned NumConds = MCDCBuilder.getTotalConditionsAndReset(E);
 if (NumConds == 0)
   return;
 
+// Extract [ID, Conds] to construct the graph.
+llvm::SmallVector CondIDs(NumConds);
+for (const auto  : ArrayRef(SourceRegions).slice(Since)) {
+  if (SR.isMCDCBranch()) {

chapuni wrote:

I think `make_filter_range` is less suitable here.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Rework !SystemHeadersCoverage (PR #91446)

2024-05-08 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/91446

- Introduce `LeafExprSet`,
  - Suppress traversing LAnd and LOr expr under system headers.
  - Handle LAnd and LOr as instrumented leaves to override 
`!isInstrumentedCondition(C)`.
- Replace Loc with FileLoc if it is expanded with system headers.

Fixes #78920

>From d3ee2d086d07ce0803117ec9fa16ac72801619c7 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Thu, 2 May 2024 09:36:39 +0900
Subject: [PATCH] [Coverage] Rework !SystemHeadersCoverage

- Introduce `LeafExprSet`,
  - Suppress traversing LAnd and LOr expr under system headers.
  - Handle LAnd and LOr as instrumented leaves to override
`!isInstrumentedCondition(C)`.
- Replace Loc with FileLoc if it is expanded with system headers.

Fixes #78920
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 48 +++---
 .../CoverageMapping/mcdc-system-headers.cpp   | 50 +++
 2 files changed, 92 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-system-headers.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d..15d7199e95b0f 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
@@ -339,16 +340,26 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Loc with FileLoc if it is expanded with system headers.
+  if (!SystemHeadersCoverage && SM.isInSystemMacro(Loc)) {
+auto BeginLoc = SM.getSpellingLoc(Loc);
+auto EndLoc = SM.getSpellingLoc(Region.getEndLoc());
+if (SM.isWrittenInSameFile(BeginLoc, EndLoc)) {
+  Loc = SM.getFileLoc(Loc);
+  Region.setStartLoc(Loc);
+  Region.setEndLoc(SM.getFileLoc(Region.getEndLoc()));
+}
+  }
+
   FileID File = SM.getFileID(Loc);
   if (!Visited.insert(File).second)
 continue;
 
-  // Do not map FileID's associated with system headers unless collecting
-  // coverage from system headers is explicitly enabled.
-  if (!SystemHeadersCoverage && 
SM.isInSystemHeader(SM.getSpellingLoc(Loc)))
-continue;
+  assert(SystemHeadersCoverage ||
+ !SM.isInSystemHeader(SM.getSpellingLoc(Loc)));
 
   unsigned Depth = 0;
   for (SourceLocation Parent = getIncludeOrExpansionLoc(Loc);
@@ -821,6 +832,10 @@ struct CounterCoverageMappingBuilder
   /// A stack of currently live regions.
   llvm::SmallVector RegionStack;
 
+  /// Set if the Expr should be handled as a leaf even if it is kind of binary
+  /// logical ops (&&, ||).
+  llvm::DenseSet LeafExprSet;
+
   /// An object to manage MCDC regions.
   MCDCCoverageBuilder MCDCBuilder;
 
@@ -1043,7 +1058,10 @@ struct CounterCoverageMappingBuilder
 // region onto RegionStack but immediately pop it (which adds it to the
 // function's SourceRegions) because it doesn't apply to any other source
 // code other than the Condition.
-if (CodeGenFunction::isInstrumentedCondition(C)) {
+// With !SystemHeadersCoverage, binary logical ops in system headers may be
+// treated as instrumentable conditions.
+if (CodeGenFunction::isInstrumentedCondition(C) ||
+LeafExprSet.count(CodeGenFunction::stripCond(C))) {
   mcdc::Parameters BranchParams;
   mcdc::ConditionID ID = MCDCBuilder.getCondID(C);
   if (ID >= 0)
@@ -2064,7 +2082,20 @@ struct CounterCoverageMappingBuilder
 createDecisionRegion(E, DecisionParams);
   }
 
+  /// Check if E belongs to system headers.
+  bool isExprInSystemHeader(const BinaryOperator *E) const {
+return (!SystemHeadersCoverage &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getOperatorLoc())) &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getBeginLoc())) &&
+SM.isInSystemHeader(SM.getSpellingLoc(E->getEndLoc(;
+  }
+
   void VisitBinLAnd(const BinaryOperator *E) {
+if (isExprInSystemHeader(E)) {
+  LeafExprSet.insert(E);
+  return;
+}
+
 bool IsRootNode = MCDCBuilder.isIdle();
 
 // Keep track of Binary Operator and assign MCDC condition IDs.
@@ -2119,6 +2150,11 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitBinLOr(const BinaryOperator *E) {
+if (isExprInSystemHeader(E)) {
+  LeafExprSet.insert(E);
+  return;
+}
+
 bool IsRootNode = MCDCBuilder.isIdle();
 
 // Keep track of Binary Operator and assign MCDC condition IDs.
diff --git a/clang/test/CoverageMapping/mcdc-system-headers.cpp 

[clang] [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (PR #89906)

2024-04-28 Thread NAKAMURA Takumi via cfe-commits


@@ -1115,7 +1115,9 @@ int64_t Decl::getID() const {
 
 const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
   QualType Ty;
-  if (const auto *D = dyn_cast(this))
+  if (const auto *D = dyn_cast(this))

chapuni wrote:

Seems causes the warning. `[-Wunused-but-set-variable]`

https://github.com/llvm/llvm-project/pull/89906
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -292,10 +292,36 @@ class CoverageMappingBuilder {
 return SM.getLocForEndOfFile(SM.getFileID(Loc));
   }
 
-  /// Find out where the current file is included or macro is expanded.
-  SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc) {
-return Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getBegin()
-   : SM.getIncludeLoc(SM.getFileID(Loc));
+  /// Find out where a macro is expanded. If the immediate result is a
+  /// , keep looking until the result isn't. Return the source
+  /// range of the found result, or std::nullopt if the while loop didn't get
+  /// executed, which means the location wasn't changed.
+  std::optional getNonScratchExpansion(SourceLocation Loc) {
+std::optional EndLoc = std::nullopt;
+while (Loc.isMacroID() &&
+   SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
+  auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
+  Loc = ExpansionRange.getBegin();
+  EndLoc = ExpansionRange.getEnd();
+}
+if (EndLoc.has_value())
+  return SourceRange(Loc, EndLoc.value());

chapuni wrote:

I wrongly supposed `isWrittenInScratchSpace()` would return `SourceRange`. 
Actually returns `CharSourceRange`.

You may rewind them with your previous change, if you prefer. The current 
implementation is not clean a bit.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni commented:

They could be simpler if `SourceRegion` were compatible to `std::pair`.
(I don't require you to work)

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -339,8 +365,17 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Region with its definition if it is in .
+  auto NonScratchExpansionLoc = getNonScratchExpansionLoc(Loc);
+  Loc = NonScratchExpansionLoc.first;
+  auto EndLoc = NonScratchExpansionLoc.second;
+  Region.setStartLoc(Loc);
+  Region.setEndLoc(EndLoc.has_value() ? EndLoc.value()
+  : Region.getEndLoc());

chapuni wrote:

Could you make updates optional?

```
if (has_value) {
  Loc = ...;
  Region.set(...);
}
```

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -292,10 +292,36 @@ class CoverageMappingBuilder {
 return SM.getLocForEndOfFile(SM.getFileID(Loc));
   }
 
-  /// Find out where the current file is included or macro is expanded.
-  SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc) {
-return Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getBegin()
-   : SM.getIncludeLoc(SM.getFileID(Loc));
+  /// Find out where a macro is expanded. If the immediate result is a
+  /// , keep looking until the result isn't. Return a pair of
+  /// \c SourceLocation. The first object is always the begin sloc of found
+  /// result. The second should be checked by the caller: if it has value, it's
+  /// the end sloc of the found result. Otherwise the while loop didn't get
+  /// executed, which means the location wasn't changed and the caller has to
+  /// learn the end sloc from somewhere else.
+  std::pair>

chapuni wrote:

Could it return `optional`?

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -292,10 +292,22 @@ class CoverageMappingBuilder {
 return SM.getLocForEndOfFile(SM.getFileID(Loc));
   }
 
-  /// Find out where the current file is included or macro is expanded.
-  SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc) {
-return Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getBegin()
-   : SM.getIncludeLoc(SM.getFileID(Loc));
+  /// Find out where the current file is included or macro is expanded. If
+  /// \c AcceptScratch is set to false, keep looking for expansions until the
+  /// found sloc is not a 
+  SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc,
+  bool AcceptScratch = true) {
+if (Loc.isMacroID()) {
+  Loc = SM.getImmediateExpansionRange(Loc).getBegin();
+  if (!AcceptScratch)
+while (Loc.isMacroID() &&
+   SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
+  auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
+  Loc = ExpansionRange.getBegin();
+}
+} else
+  Loc = SM.getIncludeLoc(SM.getFileID(Loc));

chapuni wrote:

We prefer early return.

```
if (!Loc.isMacroID())
  return SM.getIncludeLoc(...);
Loc = ...;
if (AcceptScratch)
  return Loc;
while (...)
  ...
```
```

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni commented:

I've confirmed this works. I'd like to wait for other opinions.

My comments are just my preferences.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -339,8 +355,18 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Region with its definition if it is in .
+  while (Loc.isMacroID() &&
+ SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
+auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
+Loc = ExpansionRange.getBegin();
+Region.setStartLoc(Loc);
+Region.setEndLoc(ExpansionRange.getEnd());
+  }

chapuni wrote:

Could we split out and unify this?

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits


@@ -298,6 +298,22 @@ class CoverageMappingBuilder {
: SM.getIncludeLoc(SM.getFileID(Loc));
   }
 
+  /// Find out where the current file is included or macro is expanded. If the
+  /// found expansion is a , keep looking.
+  SourceLocation getIncludeOrNonScratchExpansionLoc(SourceLocation Loc) {

chapuni wrote:

This may be integrated to `getIncludeOrExpansionLoc(FoldScratch=true)` as an 
optional behavior.

https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/89869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Workaround for `##` conditions (PR #89573)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/89573
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Workaround for `##` conditions (PR #89573)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

See #89869 .

https://github.com/llvm/llvm-project/pull/89573
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Workaround for `##` conditions (PR #89573)

2024-04-24 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@whentojump Thanks. Would you like to take this over? Then I will close this.

https://github.com/llvm/llvm-project/pull/89573
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MC/DC][Coverage] Workaround for `##` conditions (PR #89573)

2024-04-22 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/89573

A synthesized identifier with `##` is emitted to ``. `llvm-cov` 
cannot handle ` since it doesn't have actual files.

As a workaround, peel `` to the actual definition if the 
definition is present.

This affects predefined built-in macros, like __LINE__.

Fixes #87000

>From f1214b72c842d08cb843e90a7b1cace0aa6e0260 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 19 Apr 2024 15:16:05 +0900
Subject: [PATCH] [MC/DC][Coverage] Workaround for `##` conditions

A synthesized identifier with `##` is emitted to ``.
`llvm-cov` cannot handle ` since it doesn't have actual files.

As a workaround, peel `` to the actual definition if the 
definition is present.

This affects predefined built-in macros, like __LINE__.

Fixes #87000
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 12 +-
 clang/test/CoverageMapping/builtinmacro.c |  2 +-
 clang/test/CoverageMapping/macros.c   |  8 ++--
 .../test/CoverageMapping/mcdc-scratch-space.c | 39 +++
 4 files changed, 56 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-scratch-space.c

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..643f3c5ab8d349 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -339,8 +339,18 @@ class CoverageMappingBuilder {
 
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
-for (const auto  : SourceRegions) {
+for (auto  : SourceRegions) {
   SourceLocation Loc = Region.getBeginLoc();
+
+  // Replace Region with its definition if it is in .
+  while (Loc.isMacroID() &&
+ SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
+auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
+Loc = ExpansionRange.getBegin();
+Region.setStartLoc(Loc);
+Region.setEndLoc(ExpansionRange.getEnd());
+  }
+
   FileID File = SM.getFileID(Loc);
   if (!Visited.insert(File).second)
 continue;
diff --git a/clang/test/CoverageMapping/builtinmacro.c 
b/clang/test/CoverageMapping/builtinmacro.c
index abcdc191523a5d..5d5a176aa7d87e 100644
--- a/clang/test/CoverageMapping/builtinmacro.c
+++ b/clang/test/CoverageMapping/builtinmacro.c
@@ -4,7 +4,7 @@
 
 // CHECK: filename
 const char *filename (const char *name) { // CHECK-NEXT: File 0, [[@LINE]]:41 
-> [[@LINE+3]]:2 = #0
-  static const char this_file[] = __FILE__;
+  static const char this_file[] = __FILE__; // CHECK-NEXT: File 0, 
[[@LINE]]:35 -> [[@LINE]]:35 = #0
   return this_file;
 }
 
diff --git a/clang/test/CoverageMapping/macros.c 
b/clang/test/CoverageMapping/macros.c
index 6bd3be434139a2..fcf21170ef135c 100644
--- a/clang/test/CoverageMapping/macros.c
+++ b/clang/test/CoverageMapping/macros.c
@@ -80,12 +80,14 @@ void func7(void) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> 
[[@LINE+6]]:2 = #0
   int kk,ll;   // CHECK-NEXT: File 0, [[@LINE+1]]:7 -> [[@LINE+1]]:8 = #0
   if (k)   // CHECK-NEXT: Branch,File 0, [[@LINE]]:7 -> [[@LINE]]:8 = 
#1
 m(k);  // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:9 -> [[@LINE]]:5 = #1
-  else // CHECK-NEXT: Expansion,File 0, [[@LINE-1]]:5 -> 
[[@LINE-1]]:6 = #0
+  else // CHECK-NEXT: Expansion,File 0, [[@LINE-1]]:5 -> 
[[@LINE-1]]:6 = #1
 l = m(l);  // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:7 -> [[@LINE]]:5 = 
(#0 - #1)
 }  // CHECK-NEXT: File 0, [[@LINE-1]]:5 -> [[@LINE-1]]:10 = 
(#0 - #1)
// CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> 
[[@LINE-2]]:10 = (#0 - #1)
-   // CHECK-NEXT: File 1, [[@LINE-9]]:14 -> [[@LINE-9]]:18 = #0
-   // CHECK-NEXT: File 2, [[@LINE-10]]:14 -> [[@LINE-10]]:15 = 
(#0 - #1)
+   // CHECK-NEXT: File 1, [[@LINE-9]]:14 -> [[@LINE-9]]:17 = #1
+   // CHECK-NEXT: File 1, [[@LINE-10]]:14 -> [[@LINE-10]]:18 = 
#0
+   // CHECK-NEXT: File 2, [[@LINE-11]]:14 -> [[@LINE-11]]:17 = 
(#0 - #1)
+   // CHECK-NEXT: File 2, [[@LINE-12]]:14 -> [[@LINE-12]]:15 = 
(#0 - #1)
 
 int main(int argc, const char *argv[]) {
   func();
diff --git a/clang/test/CoverageMapping/mcdc-scratch-space.c 
b/clang/test/CoverageMapping/mcdc-scratch-space.c
new file mode 100644
index 00..1b8735cd27445a
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-scratch-space.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK: builtin_macro0:
+int builtin_macro0(int a) {
+  // CHECK: Decision,File 0, [[@LINE+1]]:11 -> [[@LINE+2]]:15 = M:0, C:2
+  return (__LINE__ // CHECK: Branch,File 0, [[@LINE]]:11 -> [[@LINE]]:11 = 0, 
0 [1,2,0]
+  && a); //   CHECK: Branch,File 0, [[@LINE]]:14 -> 

[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-04-22 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/89572

>From 13035b230fd51422f6c3223fcffab4f44bd00956 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 19 Apr 2024 15:26:34 +0900
Subject: [PATCH 1/2] [MC/DC][Coverage] Add assertions into emitSourceRegions()

`emitSourceRegions()` has bugs to emit malformed MC/DC coverage mappings.
They were detected in `llvm-cov` as the crash.

Detect inconsistencies earlier in `clang` with assertions.

* mcdc-system-headers.cpp covers #78920.
* mcdc-scratch-space.c covers #87000.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 29 ++--
 .../test/CoverageMapping/mcdc-scratch-space.c | 27 +++
 .../CoverageMapping/mcdc-system-headers.cpp   | 47 +++
 3 files changed, 98 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-scratch-space.c
 create mode 100644 clang/test/CoverageMapping/mcdc-system-headers.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..95ad1967c8b673 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -190,11 +190,21 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {
+return mcdc::getParams(MCDCParams);
+  }
+
   bool isMCDCDecision() const {
 const auto *DecisionParams =
 std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+assert(DecisionParams == nullptr || DecisionParams->NumConditions > 0);
+return (DecisionParams != nullptr);
   }
 
   const auto () const {
@@ -464,13 +474,19 @@ class CoverageMappingBuilder {
   // Ignore regions from system headers unless collecting coverage from
   // system headers is explicitly enabled.
   if (!SystemHeadersCoverage &&
-  SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
+  SM.isInSystemHeader(SM.getSpellingLoc(LocStart))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in system headers");
 continue;
+  }
 
   auto CovFileID = getCoverageFileID(LocStart);
   // Ignore regions that don't have a file, such as builtin macros.
-  if (!CovFileID)
+  if (!CovFileID) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in non-file regions");
 continue;
+  }
 
   SourceLocation LocEnd = Region.getEndLoc();
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
@@ -480,8 +496,11 @@ class CoverageMappingBuilder {
   // This not only suppresses redundant regions, but sometimes prevents
   // creating regions with wrong counters if, for example, a statement's
   // body ends at the end of a nested macro.
-  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+  if (Filter.count(std::make_pair(LocStart, LocEnd))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition");
 continue;
+  }
 
   // Find the spelling locations for the mapping region.
   SpellingRegion SR{SM, LocStart, LocEnd};
diff --git a/clang/test/CoverageMapping/mcdc-scratch-space.c 
b/clang/test/CoverageMapping/mcdc-scratch-space.c
new file mode 100644
index 00..962d10653a028b
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-scratch-space.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s
+// XFAIL: *
+// REQUIRES: asserts
+
+int builtin_macro0(int a) {
+  return (__LINE__
+  && a);
+}
+
+int builtin_macro1(int a) {
+  return (a
+  || __LINE__);
+}
+
+#define PRE(x) pre_##x
+
+int pre0(int pre_a, int b_post) {
+  return (PRE(a)
+  && b_post);
+}
+
+#define POST(x) x##_post
+
+int post0(int pre_a, int b_post) {
+  return (pre_a
+  || POST(b));
+}
diff --git a/clang/test/CoverageMapping/mcdc-system-headers.cpp 
b/clang/test/CoverageMapping/mcdc-system-headers.cpp
new file mode 100644
index 00..329bb37822a9ea
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-system-headers.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping  -fcoverage-mcdc -mllvm -system-headers-coverage 
-emit-llvm-only -o - %s | FileCheck %s
+
+// Will crash w/o -system-headers-coverage
+// RUN: not --crash %clang_cc1 -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -fcoverage-mcdc -emit-llvm-only -o - 
%s
+// REQUIRES: asserts
+
+#ifdef 

[clang] [MC/DC][Coverage] Add assertions into emitSourceRegions() (PR #89572)

2024-04-22 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/89572

`emitSourceRegions()` has bugs to emit malformed MC/DC coverage mappings. They 
were detected in `llvm-cov` as the crash.

Detect inconsistencies earlier in `clang` with assertions.

* mcdc-system-headers.cpp covers #78920.
* mcdc-scratch-space.c covers #87000.

>From 13035b230fd51422f6c3223fcffab4f44bd00956 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 19 Apr 2024 15:26:34 +0900
Subject: [PATCH] [MC/DC][Coverage] Add assertions into emitSourceRegions()

`emitSourceRegions()` has bugs to emit malformed MC/DC coverage mappings.
They were detected in `llvm-cov` as the crash.

Detect inconsistencies earlier in `clang` with assertions.

* mcdc-system-headers.cpp covers #78920.
* mcdc-scratch-space.c covers #87000.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 29 ++--
 .../test/CoverageMapping/mcdc-scratch-space.c | 27 +++
 .../CoverageMapping/mcdc-system-headers.cpp   | 47 +++
 3 files changed, 98 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CoverageMapping/mcdc-scratch-space.c
 create mode 100644 clang/test/CoverageMapping/mcdc-system-headers.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..95ad1967c8b673 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -190,11 +190,21 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
+  bool isMCDCBranch() const {
+const auto *BranchParams = 
std::get_if();
+assert(BranchParams == nullptr || BranchParams->ID >= 0);
+return (BranchParams != nullptr);
+  }
+
+  const auto () const {
+return mcdc::getParams(MCDCParams);
+  }
+
   bool isMCDCDecision() const {
 const auto *DecisionParams =
 std::get_if();
-assert(!DecisionParams || DecisionParams->NumConditions > 0);
-return DecisionParams;
+assert(DecisionParams == nullptr || DecisionParams->NumConditions > 0);
+return (DecisionParams != nullptr);
   }
 
   const auto () const {
@@ -464,13 +474,19 @@ class CoverageMappingBuilder {
   // Ignore regions from system headers unless collecting coverage from
   // system headers is explicitly enabled.
   if (!SystemHeadersCoverage &&
-  SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
+  SM.isInSystemHeader(SM.getSpellingLoc(LocStart))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in system headers");
 continue;
+  }
 
   auto CovFileID = getCoverageFileID(LocStart);
   // Ignore regions that don't have a file, such as builtin macros.
-  if (!CovFileID)
+  if (!CovFileID) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition in non-file regions");
 continue;
+  }
 
   SourceLocation LocEnd = Region.getEndLoc();
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
@@ -480,8 +496,11 @@ class CoverageMappingBuilder {
   // This not only suppresses redundant regions, but sometimes prevents
   // creating regions with wrong counters if, for example, a statement's
   // body ends at the end of a nested macro.
-  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+  if (Filter.count(std::make_pair(LocStart, LocEnd))) {
+assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
+   "Don't suppress the condition");
 continue;
+  }
 
   // Find the spelling locations for the mapping region.
   SpellingRegion SR{SM, LocStart, LocEnd};
diff --git a/clang/test/CoverageMapping/mcdc-scratch-space.c 
b/clang/test/CoverageMapping/mcdc-scratch-space.c
new file mode 100644
index 00..962d10653a028b
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-scratch-space.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s
+// XFAIL: *
+// REQUIRES: asserts
+
+int builtin_macro0(int a) {
+  return (__LINE__
+  && a);
+}
+
+int builtin_macro1(int a) {
+  return (a
+  || __LINE__);
+}
+
+#define PRE(x) pre_##x
+
+int pre0(int pre_a, int b_post) {
+  return (PRE(a)
+  && b_post);
+}
+
+#define POST(x) x##_post
+
+int post0(int pre_a, int b_post) {
+  return (pre_a
+  || POST(b));
+}
diff --git a/clang/test/CoverageMapping/mcdc-system-headers.cpp 
b/clang/test/CoverageMapping/mcdc-system-headers.cpp
new file mode 100644
index 00..329bb37822a9ea
--- /dev/null
+++ b/clang/test/CoverageMapping/mcdc-system-headers.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping  -fcoverage-mcdc -mllvm -system-headers-coverage 

[clang] 36e2577 - clang/test/APINotes/instancetype.m: Clean the cache dir

2024-04-09 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-04-10T10:14:22+09:00
New Revision: 36e25772ddd049c8c742e55fbd2b3c9aaceb7060

URL: 
https://github.com/llvm/llvm-project/commit/36e25772ddd049c8c742e55fbd2b3c9aaceb7060
DIFF: 
https://github.com/llvm/llvm-project/commit/36e25772ddd049c8c742e55fbd2b3c9aaceb7060.diff

LOG: clang/test/APINotes/instancetype.m: Clean the cache dir

It has been incompatible since #87761

Added: 


Modified: 
clang/test/APINotes/instancetype.m

Removed: 




diff  --git a/clang/test/APINotes/instancetype.m 
b/clang/test/APINotes/instancetype.m
index 30339e5386f634..e3c13188ae9f78 100644
--- a/clang/test/APINotes/instancetype.m
+++ b/clang/test/APINotes/instancetype.m
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fsyntax-only -I 
%S/Inputs/Headers -verify %s
 
 @import InstancetypeModule;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d08a76d - Fix warnings discovered by #87348 [-Wunused-but-set-variable]

2024-04-06 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-04-07T11:02:08+09:00
New Revision: d08a76d1ac1ba6b376faa908ccbaaabc999dfbc5

URL: 
https://github.com/llvm/llvm-project/commit/d08a76d1ac1ba6b376faa908ccbaaabc999dfbc5
DIFF: 
https://github.com/llvm/llvm-project/commit/d08a76d1ac1ba6b376faa908ccbaaabc999dfbc5.diff

LOG: Fix warnings discovered by #87348 [-Wunused-but-set-variable]

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Sema/SemaOverload.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46182809810bcf..50e86d94736476 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2511,6 +2511,7 @@ unsigned 
ByteCodeExprGen::allocateLocalPrimitive(DeclTy &,
   dyn_cast_if_present(Src.dyn_cast())) {
 assert(!P.getGlobal(VD));
 assert(!Locals.contains(VD));
+(void)VD;
   }
 
   // FIXME: There are cases where Src.is() is wrong, e.g.

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 70ac0764476f60..1bfa7ebcfd50c9 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -850,6 +850,7 @@ void Environment::setValue(const Expr , Value ) {
   if (auto *RecordVal = dyn_cast()) {
 assert(isOriginalRecordConstructor(CanonE) ||
>getLoc() == (CanonE));
+(void)RecordVal;
   }
 
   assert(CanonE.isPRValue());

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c913bc700f4a1..3808af37ff54a8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6354,6 +6354,7 @@ Sema::EvaluateConvertedConstantExpression(Expr *E, 
QualType T, APValue ,
 // by this point.
 assert(CE->getResultStorageKind() != ConstantResultStorageKind::None &&
"ConstantExpr has no value associated with it");
+(void)CE;
   } else {
 E = ConstantExpr::Create(Context, Result.get(), Value);
   }

diff  --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp 
b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 915cd81661f027..5396038d8b92b7 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -784,7 +784,7 @@ BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock 
*Succ, DominatorTree *DT,
 // If the successor only has a single pred, split the top of the successor
 // block.
 assert(SP == BB && "CFG broken");
-SP = nullptr;
+(void)SP;
 return SplitBlock(Succ, >front(), DT, LI, MSSAU, BBName,
   /*Before=*/true);
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-27 Thread NAKAMURA Takumi via cfe-commits


@@ -1503,38 +1527,53 @@ struct CounterCoverageMappingBuilder
 }
 
 // Create Branch Region around condition.
-createBranchRegion(S->getCond(), BodyCount,
-   subtractCounters(CondCount, BodyCount));
+if (!llvm::EnableSingleByteCoverage)
+  createBranchRegion(S->getCond(), BodyCount,
+ subtractCounters(CondCount, BodyCount));

chapuni wrote:

As far as I have checked, I guess `!EnableSingleByteCoverage` can be sunk into 
`createBranchRegion()` rather than checking from callers.

Sorry for my delayed comment. I didn't notice till merging.

https://github.com/llvm/llvm-project/pull/75425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits


@@ -1201,19 +1197,22 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
   // Extract the ID of the condition we are setting in the bitmap.
   const auto  = BranchStateIter->second;
   assert(Branch.ID >= 0 && "Condition has no ID!");
+  assert(Branch.DecisionStmt);
 
-  auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
+  // Cancel the emission if the Decision is erased after the allocation.
+  const auto DecisionIter =
+  RegionMCDCState->DecisionByStmt.find(Branch.DecisionStmt);
+  if (DecisionIter == RegionMCDCState->DecisionByStmt.end())
+return;
 
-  // Emit intrinsic that updates a dedicated temporary value on the stack after
-  // a condition is evaluated. After the set of conditions has been updated,
-  // the resulting value is used to update the boolean expression's bitmap.
-  llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
-  Builder.getInt64(FunctionHash),
-  Builder.getInt32(Branch.ID),
-  MCDCCondBitmapAddr.getPointer(), Val};
-  Builder.CreateCall(
-  CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
-  Args);
+  const auto  = DecisionIter->second.Indices[Branch.ID];
+
+  auto *CurTV = Builder.CreateLoad(MCDCCondBitmapAddr,
+   "mcdc." + Twine(Branch.ID + 1) + ".cur");
+  auto *NewTV = Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[true]));
+  NewTV = Builder.CreateSelect(
+  Val, NewTV, Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[false])));
+  Builder.CreateStore(NewTV, MCDCCondBitmapAddr);

chapuni wrote:

I don't think it wouldn't make sense to make this as the intrinsic, because 
this doesn't operate special operations. I'd like to create cleanups later to 
prune `condbitmap_update` since pruning is not the prerequisite of this change.

In contrast, I think `tvbitmap` may be left, because it could emit atomic 
operations as options.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits


@@ -1128,9 +1122,11 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy 
) {
   // Emit intrinsic representing MCDC bitmap parameters at function entry.
   // This is used by the instrumentation pass, but it isn't actually lowered to
   // anything.
-  llvm::Value *Args[3] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
-  Builder.getInt64(FunctionHash),
-  Builder.getInt32(RegionMCDCState->BitmapBytes)};
+  llvm::Value *Args[3] = {
+  llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
+  Builder.getInt64(FunctionHash),
+  Builder.getInt32(llvm::alignTo(RegionMCDCState->BitmapBits, CHAR_BIT) /
+   CHAR_BIT)};

chapuni wrote:

@evodius96 Could we change it with bitcount as well, for the consistency?

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits


@@ -1201,19 +1197,22 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
   // Extract the ID of the condition we are setting in the bitmap.
   const auto  = BranchStateIter->second;
   assert(Branch.ID >= 0 && "Condition has no ID!");
+  assert(Branch.DecisionStmt);
 
-  auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
+  // Cancel the emission if the Decision is erased after the allocation.
+  const auto DecisionIter =
+  RegionMCDCState->DecisionByStmt.find(Branch.DecisionStmt);
+  if (DecisionIter == RegionMCDCState->DecisionByStmt.end())
+return;
 
-  // Emit intrinsic that updates a dedicated temporary value on the stack after
-  // a condition is evaluated. After the set of conditions has been updated,
-  // the resulting value is used to update the boolean expression's bitmap.
-  llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
-  Builder.getInt64(FunctionHash),
-  Builder.getInt32(Branch.ID),
-  MCDCCondBitmapAddr.getPointer(), Val};
-  Builder.CreateCall(
-  CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
-  Args);
+  const auto  = DecisionIter->second.Indices[Branch.ID];
+
+  auto *CurTV = Builder.CreateLoad(MCDCCondBitmapAddr,
+   "mcdc." + Twine(Branch.ID + 1) + ".cur");
+  auto *NewTV = Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[true]));
+  NewTV = Builder.CreateSelect(
+  Val, NewTV, Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[false])));
+  Builder.CreateStore(NewTV, MCDCCondBitmapAddr);

chapuni wrote:

I don't use the intrinsic.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits


@@ -973,9 +970,11 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
   auto *MCDCCondBitmapAddr = Update->getMCDCCondBitmapAddr();
   auto *BitmapAddr = getBitmapAddress(Update);
 
-  // Load Temp Val.
+  // Load Temp Val + BitmapIdx.
   //  %mcdc.temp = load i32, ptr %mcdc.addr, align 4
-  auto *Temp = Builder.CreateLoad(Int32Ty, MCDCCondBitmapAddr, "mcdc.temp");
+  auto *Temp = Builder.CreateAdd(
+  Builder.CreateLoad(Int32Ty, MCDCCondBitmapAddr, "mcdc.temp"),
+  Update->getBitmapIndex());

chapuni wrote:

`tvupdate`'s Index points to the bit index in the bitmap.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni commented:

TODO:

* Version bump in file formats (wip)
* Update documents

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni ready_for_review 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-26 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0c7a605 - clangCodeGen: [MC/DC] Refactor CoverageGen.

2024-02-25 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-26T16:44:19+09:00
New Revision: 0c7a605ada6cb392e6e8c16dbccf2b7e59017399

URL: 
https://github.com/llvm/llvm-project/commit/0c7a605ada6cb392e6e8c16dbccf2b7e59017399
DIFF: 
https://github.com/llvm/llvm-project/commit/0c7a605ada6cb392e6e8c16dbccf2b7e59017399.diff

LOG: clangCodeGen: [MC/DC] Refactor CoverageGen.

- Introduce `createDecision(E)` for the root node of `VisitBin`.
- Handle `mcdc::DecisionParameters` for each Decision method.

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index d98ab79eac3aed..e25a92758f32b7 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -852,10 +852,6 @@ struct CounterCoverageMappingBuilder
 return Counter::getCounter(CounterMap[S]);
   }
 
-  auto getBitmapIdx(const Stmt *S) {
-return MCDCState.DecisionByStmt[S].BitmapIdx;
-  }
-
   /// Push a region onto the stack.
   ///
   /// Returns the index on the stack where the region was pushed. This can be
@@ -888,12 +884,11 @@ struct CounterCoverageMappingBuilder
 return RegionStack.size() - 1;
   }
 
-  size_t pushRegion(unsigned BitmapIdx, uint16_t Conditions,
+  size_t pushRegion(const mcdc::DecisionParameters ,
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt) {
 
-RegionStack.emplace_back(mcdc::DecisionParameters{BitmapIdx, Conditions},
- StartLoc, EndLoc);
+RegionStack.emplace_back(DecisionParams, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
   }
@@ -1059,8 +1054,9 @@ struct CounterCoverageMappingBuilder
   /// Create a Decision Region with a BitmapIdx and number of Conditions. This
   /// type of region "contains" branch regions, one for each of the conditions.
   /// The visualization tool will group everything together.
-  void createDecisionRegion(const Expr *C, unsigned BitmapIdx, unsigned Conds) 
{
-popRegions(pushRegion(BitmapIdx, Conds, getStart(C), getEnd(C)));
+  void createDecisionRegion(const Expr *C,
+const mcdc::DecisionParameters ) {
+popRegions(pushRegion(DecisionParams, getStart(C), getEnd(C)));
   }
 
   /// Create a Branch Region around a SwitchCase for code coverage
@@ -1312,7 +1308,7 @@ struct CounterCoverageMappingBuilder
   return;
 assert(SpellingRegion(SM, NewStartLoc, EndLoc).isInSourceOrder());
 handleFileExit(NewStartLoc);
-size_t Index = pushRegion({}, NewStartLoc, EndLoc);
+size_t Index = pushRegion(Counter{}, NewStartLoc, EndLoc);
 getRegion().setSkipped(true);
 handleFileExit(EndLoc);
 popRegions(Index);
@@ -1962,6 +1958,20 @@ struct CounterCoverageMappingBuilder
subtractCounters(ParentCount, TrueCount));
   }
 
+  void createDecision(const BinaryOperator *E) {
+unsigned NumConds = MCDCBuilder.getTotalConditionsAndReset(E);
+if (NumConds == 0)
+  return;
+
+auto DecisionParams = mcdc::DecisionParameters{
+MCDCState.DecisionByStmt[E].BitmapIdx,
+NumConds,
+};
+
+// Create MCDC Decision Region.
+createDecisionRegion(E, DecisionParams);
+  }
+
   void VisitBinLAnd(const BinaryOperator *E) {
 bool IsRootNode = MCDCBuilder.isIdle();
 
@@ -1982,11 +1992,6 @@ struct CounterCoverageMappingBuilder
 // Track RHS True/False Decision.
 const auto DecisionRHS = MCDCBuilder.back();
 
-// Create MCDC Decision Region if at top-level (root).
-unsigned NumConds = 0;
-if (IsRootNode && (NumConds = MCDCBuilder.getTotalConditionsAndReset(E)))
-  createDecisionRegion(E, getBitmapIdx(E), NumConds);
-
 // Extract the RHS's Execution Counter.
 Counter RHSExecCnt = getRegionCounter(E);
 
@@ -2003,6 +2008,10 @@ struct CounterCoverageMappingBuilder
 // Create Branch Region around RHS condition.
 createBranchRegion(E->getRHS(), RHSTrueCnt,
subtractCounters(RHSExecCnt, RHSTrueCnt), DecisionRHS);
+
+// Create MCDC Decision Region if at top-level (root).
+if (IsRootNode)
+  createDecision(E);
   }
 
   // Determine whether the right side of OR operation need to be visited.
@@ -2035,11 +2044,6 @@ struct CounterCoverageMappingBuilder
 // Track RHS True/False Decision.
 const auto DecisionRHS = MCDCBuilder.back();
 
-// Create MCDC Decision Region if at top-level (root).
-unsigned NumConds = 0;
-if (IsRootNode && (NumConds = MCDCBuilder.getTotalConditionsAndReset(E)))
-  createDecisionRegion(E, getBitmapIdx(E), NumConds);
-
 // Extract the RHS's Execution Counter.
 Counter RHSExecCnt = getRegionCounter(E);
 
@@ -2060,6 +2064,10 @@ struct CounterCoverageMappingBuilder
 // Create Branch Region around RHS condition.
 

[clang] 1f6a347 - Refactor: Let MCDC::State have DecisionByStmt and BranchByStmt

2024-02-25 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-25T18:33:53+09:00
New Revision: 1f6a347c8abf8868fb4630c404480226c2efc2c2

URL: 
https://github.com/llvm/llvm-project/commit/1f6a347c8abf8868fb4630c404480226c2efc2c2
DIFF: 
https://github.com/llvm/llvm-project/commit/1f6a347c8abf8868fb4630c404480226c2efc2c2.diff

LOG: Refactor: Let MCDC::State have DecisionByStmt and BranchByStmt

- Prune `RegionMCDCBitmapMap` and `RegionCondIDMap`. They are handled
  by `MCDCState`.
- Rename `s/BitmapMap/DecisionByStmt/`. It can handle Decision stuff.
- Rename `s/CondIDMap/BranchByStmt/`. It can be handle Branch stuff.
- `MCDCRecordProcessor`: Use `DecisionParams.BitmapIdx` directly.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/MCDCState.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 1ef7be3c72593d..8aebd3557690af 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -165,6 +165,7 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
   llvm::DenseMap 
   /// The next bitmap byte index to assign.
   unsigned NextMCDCBitmapIdx;
+  /// The state of MC/DC Coverage in this function.
   MCDC::State 
   /// Maximum number of supported MC/DC conditions in a boolean expression.
   unsigned MCDCMaxCond;
@@ -311,7 +312,7 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
 
   // Otherwise, allocate the number of bytes required for the bitmap
   // based on the number of conditions. Must be at least 1-byte long.
-  MCDCState.BitmapMap[BinOp] = NextMCDCBitmapIdx;
+  MCDCState.DecisionByStmt[BinOp].BitmapIdx = NextMCDCBitmapIdx;
   unsigned SizeInBits = std::max(1L << NumCond, CHAR_BIT);
   NextMCDCBitmapIdx += SizeInBits / CHAR_BIT;
 }
@@ -1034,7 +1035,7 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
 
   std::string CoverageMapping;
   llvm::raw_string_ostream OS(CoverageMapping);
-  RegionCondIDMap.reset(new llvm::DenseMap);
+  RegionMCDCState->BranchByStmt.clear();
   CoverageMappingGen MappingGen(
   *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(),
   CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCState.get());
@@ -1142,12 +1143,12 @@ void 
CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy ,
 
   S = S->IgnoreParens();
 
-  auto ExprMCDCBitmapMapIterator = RegionMCDCState->BitmapMap.find(S);
-  if (ExprMCDCBitmapMapIterator == RegionMCDCState->BitmapMap.end())
+  auto DecisionStateIter = RegionMCDCState->DecisionByStmt.find(S);
+  if (DecisionStateIter == RegionMCDCState->DecisionByStmt.end())
 return;
 
-  // Extract the ID of the global bitmap associated with this expression.
-  unsigned MCDCTestVectorBitmapID = ExprMCDCBitmapMapIterator->second;
+  // Extract the offset of the global bitmap associated with this expression.
+  unsigned MCDCTestVectorBitmapOffset = DecisionStateIter->second.BitmapIdx;
   auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
 
   // Emit intrinsic responsible for updating the global bitmap corresponding to
@@ -1158,7 +1159,7 @@ void 
CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy ,
   llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
   Builder.getInt64(FunctionHash),
   Builder.getInt32(RegionMCDCState->BitmapBytes),
-  Builder.getInt32(MCDCTestVectorBitmapID),
+  Builder.getInt32(MCDCTestVectorBitmapOffset),
   MCDCCondBitmapAddr.getPointer()};
   Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_tvbitmap_update), Args);
@@ -1171,7 +1172,7 @@ void CodeGenPGO::emitMCDCCondBitmapReset(CGBuilderTy 
, const Expr *S,
 
   S = S->IgnoreParens();
 
-  if (!RegionMCDCState->BitmapMap.contains(S))
+  if (!RegionMCDCState->DecisionByStmt.contains(S))
 return;
 
   // Emit intrinsic that resets a dedicated temporary value on the stack to 0.
@@ -1193,13 +1194,13 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
   // also make debugging a bit easier.
   S = CodeGenFunction::stripCond(S);
 
-  auto ExprMCDCConditionIDMapIterator = RegionMCDCState->CondIDMap.find(S);
-  if (ExprMCDCConditionIDMapIterator == RegionMCDCState->CondIDMap.end())
+  auto BranchStateIter = RegionMCDCState->BranchByStmt.find(S);
+  if (BranchStateIter == RegionMCDCState->BranchByStmt.end())
 return;
 
   // Extract the ID of the condition we are setting in the bitmap.
-  auto CondID = ExprMCDCConditionIDMapIterator->second;
-  assert(CondID >= 0 && "Condition has no ID!");
+  const auto  = BranchStateIter->second;
+  assert(Branch.ID >= 0 && "Condition 

[clang] cc53707 - LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.

2024-02-24 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-25T11:21:46+09:00
New Revision: cc53707a5c104eb7789829ecdb2e3ae2be1a42da

URL: 
https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da
DIFF: 
https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da.diff

LOG: LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.

Added: 


Modified: 
clang/test/Profile/c-mcdc-class.cpp
clang/test/Profile/c-mcdc-logicalop-ternary.c
clang/test/Profile/c-mcdc-nested-ternary.c
clang/test/Profile/c-mcdc-not.c
clang/test/Profile/c-mcdc.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/mcdc.ll

Removed: 




diff  --git a/clang/test/Profile/c-mcdc-class.cpp 
b/clang/test/Profile/c-mcdc-class.cpp
index 2206a39ee4ffb4..6aab55add32807 100644
--- a/clang/test/Profile/c-mcdc-class.cpp
+++ b/clang/test/Profile/c-mcdc-class.cpp
@@ -54,9 +54,7 @@ Value::~Value(void) {
 // UPDATE FINAL BITMASK WITH RESULT.
 // MCDCCTOR-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDCCTOR:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDCCTOR:  %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDCCTOR:  %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueC2Ev 
to i64), %[[LAB2]]
-// MCDCCTOR:  %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDCCTOR:  %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr 
@__profbm__ZN5ValueC2Ev, i32 %[[LAB1]]
 // MCDCCTOR:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDCCTOR:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDCCTOR:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -93,9 +91,7 @@ Value::~Value(void) {
 // UPDATE FINAL BITMASK WITH RESULT.
 // MCDCDTOR-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDCDTOR:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDCDTOR:  %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDCDTOR:  %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueD2Ev 
to i64), %[[LAB2]]
-// MCDCDTOR:  %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDCDTOR:  %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr 
@__profbm__ZN5ValueD2Ev, i32 %[[LAB1]]
 // MCDCDTOR:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDCDTOR:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDCDTOR:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

diff  --git a/clang/test/Profile/c-mcdc-logicalop-ternary.c 
b/clang/test/Profile/c-mcdc-logicalop-ternary.c
index 558643f422021c..3e6b6b1e380d1e 100644
--- a/clang/test/Profile/c-mcdc-logicalop-ternary.c
+++ b/clang/test/Profile/c-mcdc-logicalop-ternary.c
@@ -20,9 +20,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC-LABEL: cond.true:
 // MCDC-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDC:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC:  %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC:  %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), 
%[[LAB2]]
-// MCDC:  %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC:  %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, 
i32 %[[LAB1]]
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -38,9 +36,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC-LABEL: land.end:
 // MCDC-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDC:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC:  %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC:  %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 
x i8], ptr @__profbm_test, i32 0, i32 1) to i64), %[[LAB2]]
-// MCDC:  %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC:  %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr 
inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1), i32 %[[LAB1]]
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -52,9 +48,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC-LABEL: cond.false:
 // MCDC-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
 // MCDC:  %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC:  %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC:  %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), 
%[[LAB2]]
-// MCDC:  %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC:  %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, 
i32 %[[LAB1]]
 // MCDC:  %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
 // MCDC:  %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
 // MCDC:  %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -70,9 +64,7 @@ int test(int a, int b, int c, int d, int e, int f) {
 // MCDC-LABEL: lor.end:
 // MCDC-DAG:  %[[TEMP:mcdc.temp[0-9]*]] = load 

[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@hanickadot Your comments to `llvm/CoverageMapping.cpp` are not for this PR. 
See #80676 .

They are my preferences.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits


@@ -1959,9 +2013,44 @@ struct CounterCoverageMappingBuilder
subtractCounters(ParentCount, TrueCount));
   }
 
+  void RewindDecision(unsigned Since) {
+#ifndef NDEBUG
+llvm::DenseSet SeenIDs;
+#endif
+unsigned NConds = 0;

chapuni wrote:

Thanks. I haven't found it anyways. Will do.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits


@@ -723,7 +737,15 @@ struct MCDCCoverageBuilder {
 if (I == CondIDs.end())
   return -1;
 else
-  return I->second;
+  return I->second.ID;
+  }
+
+  void ccc(const Expr *CondExpr, mcdc::ConditionIDs IDs) {

chapuni wrote:

This is w-i-p. Thanks for pointing this out.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni commented:

Thanks for your comments and sorry for my hasty w-i-p work . I know a few rough 
implementations would be there.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits


@@ -983,7 +979,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
   // for most embedded applications. Setting a maximum value prevents the
   // bitmap footprint from growing too large without the user's knowledge. In
   // the future, this value could be adjusted with a command-line option.
-  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 6 : 0;
+  unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 32767 : 0;

chapuni wrote:

`MaxCond` is one of options. I guess it could be configurable just for theirs 
coding rules, since I think controlling `MaxCond` would not make sense.
I know we have to introduce other options as well. I will do later.
* `MaxCond`
* `MaxTVs` to restrict per-expression number of TVs
* "Max bytes of bitmap in the CU" to restict inter-function size of the bitmap.

https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-02-20 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/82448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 75f0d40 - CoverageMapping: Move `getParams(MCDCParams)` into `mcdc::`

2024-02-15 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-15T20:27:47+09:00
New Revision: 75f0d40507ea3f7c99dd3250ff0fbe6dab341910

URL: 
https://github.com/llvm/llvm-project/commit/75f0d40507ea3f7c99dd3250ff0fbe6dab341910
DIFF: 
https://github.com/llvm/llvm-project/commit/75f0d40507ea3f7c99dd3250ff0fbe6dab341910.diff

LOG: CoverageMapping: Move `getParams(MCDCParams)` into `mcdc::`

Fixup for #81227

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index eb3beec23808e6..c10d85ea89ee61 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -190,8 +190,7 @@ class SourceMappingRegion {
   }
 
   const auto () const {
-return CounterMappingRegion::getParams(
-MCDCParams);
+return mcdc::getParams(MCDCParams);
   }
 
   const mcdc::Parameters () const { return MCDCParams; }

diff  --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index e3b394287f3352..c5c9740f25c2ce 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -258,22 +258,12 @@ struct CounterMappingRegion {
   /// Parameters used for Modified Condition/Decision Coverage
   mcdc::Parameters MCDCParams;
 
-  template 
-  static auto (MaybeConstMCDCParameters ) {
-using InnerParameters =
-typename std::remove_const::type;
-MaybeConstInnerParameters *Params =
-std::get_if();
-assert(Params && "InnerParameters unavailable");
-return *Params;
-  }
-
   const auto () const {
-return getParams(MCDCParams);
+return mcdc::getParams(MCDCParams);
   }
 
   const auto () const {
-return getParams(MCDCParams);
+return mcdc::getParams(MCDCParams);
   }
 
   unsigned FileID = 0;

diff  --git a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h 
b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
index 51f528b7e78804..8c78bed4dec52f 100644
--- a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
+++ b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
@@ -14,6 +14,8 @@
 #define LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
 
 #include 
+#include 
+#include 
 #include 
 
 namespace llvm::coverage::mcdc {
@@ -49,6 +51,19 @@ struct BranchParameters {
 using Parameters =
 std::variant;
 
+/// Check and get underlying params in MCDCParams.
+/// \tparam MaybeConstInnerParameters Type to get. May be const.
+/// \tparam MaybeConstMCDCParameters Expected inferred. May be const.
+/// \param MCDCParams May be const.
+template 
+static auto (MaybeConstMCDCParameters ) {
+  using InnerParameters =
+  typename std::remove_const::type;
+  MaybeConstInnerParameters *Params = 
std::get_if();
+  assert(Params && "InnerParameters unavailable");
+  return *Params;
+}
+
 } // namespace llvm::coverage::mcdc
 
 #endif // LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3fe5a0c - MCDCCoverageBuilder: Use `pop_back_val()`

2024-02-15 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-02-15T20:27:47+09:00
New Revision: 3fe5a0cfa5391db18fcc226f3f783642d3f44503

URL: 
https://github.com/llvm/llvm-project/commit/3fe5a0cfa5391db18fcc226f3f783642d3f44503
DIFF: 
https://github.com/llvm/llvm-project/commit/3fe5a0cfa5391db18fcc226f3f783642d3f44503.diff

LOG: MCDCCoverageBuilder: Use `pop_back_val()`

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index fdf821a0eb6928..eb3beec23808e6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -770,12 +770,10 @@ struct MCDCCoverageBuilder {
   /// Pop and return the LHS Decision ([0,0] if not set).
   mcdc::ConditionIDs pop() {
 if (!CGM.getCodeGenOpts().MCDCCoverage || NotMapped)
-  return DecisionStack.front();
+  return DecisionStackSentinel;
 
 assert(DecisionStack.size() > 1);
-mcdc::ConditionIDs D = DecisionStack.back();
-DecisionStack.pop_back();
-return D;
+return DecisionStack.pop_back_val();
   }
 
   /// Return the total number of conditions and reset the state. The number of



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC] Refactor: Let MCDCConditionID int16_t with zero-origin (PR #81257)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni closed 
https://github.com/llvm/llvm-project/pull/81257
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC/DC] Refactor: Let MCDCConditionID int16_t with zero-origin (PR #81257)

2024-02-14 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/81257

>From b2e8b3eaa067844a5fa5643aca17dbb0f237182e Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Sat, 10 Feb 2024 00:08:36 +0900
Subject: [PATCH 1/2] [MC/DC] Refactor: Let MCDCConditionID int16_t with
 zero-origin

Also, Let NumConditions uint16_t
---
 clang/lib/CodeGen/CodeGenPGO.cpp  |  8 ++---
 clang/lib/CodeGen/CodeGenPGO.h|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 30 +--
 clang/lib/CodeGen/CoverageMappingGen.h|  4 +--
 .../ProfileData/Coverage/CoverageMapping.h| 10 +++
 .../ProfileData/Coverage/CoverageMapping.cpp  | 25 
 .../Coverage/CoverageMappingReader.cpp| 17 ++-
 .../Coverage/CoverageMappingWriter.cpp|  6 ++--
 .../ProfileData/CoverageMappingTest.cpp   | 18 +--
 9 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 5d7c3847745762..9025889f443b88 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1033,7 +1033,7 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
 
   std::string CoverageMapping;
   llvm::raw_string_ostream OS(CoverageMapping);
-  RegionCondIDMap.reset(new llvm::DenseMap);
+  RegionCondIDMap.reset(new llvm::DenseMap);
   CoverageMappingGen MappingGen(
   *CGM.getCoverageMapping(), CGM.getContext().getSourceManager(),
   CGM.getLangOpts(), RegionCounterMap.get(), RegionMCDCBitmapMap.get(),
@@ -1198,8 +1198,8 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
 return;
 
   // Extract the ID of the condition we are setting in the bitmap.
-  unsigned CondID = ExprMCDCConditionIDMapIterator->second;
-  assert(CondID > 0 && "Condition has no ID!");
+  auto CondID = ExprMCDCConditionIDMapIterator->second;
+  assert(CondID >= 0 && "Condition has no ID!");
 
   auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
 
@@ -1208,7 +1208,7 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy 
, const Expr *S,
   // the resulting value is used to update the boolean expression's bitmap.
   llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
   Builder.getInt64(FunctionHash),
-  Builder.getInt32(CondID - 1),
+  Builder.getInt32(CondID),
   MCDCCondBitmapAddr.getPointer(), Val};
   Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 6596b6c3527764..5f2941cfb2e95e 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -37,7 +37,7 @@ class CodeGenPGO {
   uint64_t FunctionHash;
   std::unique_ptr> RegionCounterMap;
   std::unique_ptr> RegionMCDCBitmapMap;
-  std::unique_ptr> RegionCondIDMap;
+  std::unique_ptr> RegionCondIDMap;
   std::unique_ptr> StmtCountMap;
   std::unique_ptr ProfRecord;
   std::vector RegionCounts;
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..d918acd951dd8c 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -587,8 +587,8 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 struct MCDCCoverageBuilder {
 
   struct DecisionIDPair {
-MCDCConditionID TrueID = 0;
-MCDCConditionID FalseID = 0;
+MCDCConditionID TrueID = -1;
+MCDCConditionID FalseID = -1;
   };
 
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
@@ -684,11 +684,11 @@ struct MCDCCoverageBuilder {
   llvm::SmallVector DecisionStack;
   llvm::DenseMap 
   llvm::DenseMap 
-  MCDCConditionID NextID = 1;
+  MCDCConditionID NextID = 0;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr DecisionIDPair DecisionStackSentinel{-1, -1};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -705,12 +705,12 @@ struct MCDCCoverageBuilder {
   /// Return whether the build of the control flow map is at the top-level
   /// (root) of a logical operator nest in a boolean expression prior to the
   /// assignment of condition IDs.
-  bool isIdle() const { return (NextID == 1 && !NotMapped); }
+  bool isIdle() const { return (NextID == 0 && !NotMapped); }
 
   /// Return whether any IDs have been assigned in the build of the control
   /// flow map, indicating that the map is being generated for this boolean
   /// expression.
-  bool isBuilding() const { return (NextID > 1); }
+  bool isBuilding() const { return (NextID > 0); }
 
   /// Set the given condition's ID.
   void setCondID(const Expr *Cond, 

  1   2   3   4   5   6   >