[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-09 Thread David Tellenbach via cfe-commits

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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-09 Thread David Tellenbach via cfe-commits

dtellenbach wrote:

Linux test failure seems unrelated (fails to build some libcxx stuff). The new 
test passes:

```
PASS: Clang :: CodeGen/aarch64-inlineasm-ios.c (14316 of 95454)
```




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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-08 Thread David Tellenbach via cfe-commits

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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-08 Thread David Tellenbach via cfe-commits


@@ -0,0 +1,23 @@
+// REQUIRES: aarch64-registered-target

dtellenbach wrote:

Yep, seems like I accidentally added a new folder. Targets other than AArch64 
and Arm use a subfolder but still rely on `REQUIRES`. AArch64 just dumps 
everything into the top-level test folder and thus have to rely on `REQUIRES`. 

I now move the test up to `test/CodeGen` and stick with `REQUIRES`. Should be 
reworked but not in this patch.

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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-08 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach updated 
https://github.com/llvm/llvm-project/pull/98097

>From 46e32d1156e38653c79682600fbf63d964277dba Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Mon, 8 Jul 2024 16:04:18 -0700
Subject: [PATCH 1/2] [AsmPrinter] Don't check for inlineasm dialect on non-X86
 platforms

AArch64 uses MCAsmInfo::AssemblerDialect to control the style of emitted
Neon assembly. E.g. Apple platforms use AsmWriterVariantTy::Apple by
default which collides with InlineAsm::AD_Intel (both value 1). Checking
for inlineasm dialects on non-X86 platforms can thus lead to problems.
---
 clang/test/CodeGen/AArch64/inline-asm-ios.c   | 23 +++
 .../AsmPrinter/AsmPrinterInlineAsm.cpp| 14 +++
 2 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/inline-asm-ios.c

diff --git a/clang/test/CodeGen/AArch64/inline-asm-ios.c 
b/clang/test/CodeGen/AArch64/inline-asm-ios.c
new file mode 100644
index 0..5e7328a15f69d
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/inline-asm-ios.c
@@ -0,0 +1,23 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple arm64-apple-ios -S -o - %s | FileCheck %s
+
+// CHECK:   _restartable_function:
+// CHECK-NEXT: ldr x11, [x0]
+// CHECK-NEXT: add x11, x11, #1
+// CHECK-NEXT: str x11, [x0]
+// CHECK-NEXT:  Ltmp0:
+// CHECK-NEXT: b   Ltmp0
+// CHECK-NEXT:  LExit_restartable_function:
+// CHECK-NEXT: ret
+asm(".align 4\n"
+".text\n"
+".private_extern _restartable_function\n"
+"_restartable_function:\n"
+"ldrx11, [x0]\n"
+"addx11, x11, #1\n"
+"strx11, [x0]\n"
+"1:\n"
+"b 1b\n"
+"LExit_restartable_function:\n"
+"ret\n"
+);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 5a7013c964cb4..6fe8d0e0af995 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -113,12 +113,16 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const 
MCSubtargetInfo &STI,
   if (!TAP)
 report_fatal_error("Inline asm not supported by this streamer because"
" we don't have an asm parser for this target\n");
-  Parser->setAssemblerDialect(Dialect);
+
+  // Respect inlineasm dialect on X86 targets only
+  if (TM.getTargetTriple().isX86()) {
+Parser->setAssemblerDialect(Dialect);
+// Enable lexing Masm binary and hex integer literals in intel inline
+// assembly.
+if (Dialect == InlineAsm::AD_Intel)
+  Parser->getLexer().setLexMasmIntegers(true);
+  }
   Parser->setTargetParser(*TAP);
-  // Enable lexing Masm binary and hex integer literals in intel inline
-  // assembly.
-  if (Dialect == InlineAsm::AD_Intel)
-Parser->getLexer().setLexMasmIntegers(true);
 
   emitInlineAsmStart();
   // Don't implicitly switch to the text section before the asm.

>From ca81fa117841a551702d678a6402a3bd98e85f2b Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Mon, 8 Jul 2024 18:38:32 -0700
Subject: [PATCH 2/2] Move test up into clang/test/CodeGen instead of target
 specific folder

---
 .../CodeGen/{AArch64/inline-asm-ios.c => aarch64-inlineasm-ios.c} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename clang/test/CodeGen/{AArch64/inline-asm-ios.c => 
aarch64-inlineasm-ios.c} (100%)

diff --git a/clang/test/CodeGen/AArch64/inline-asm-ios.c 
b/clang/test/CodeGen/aarch64-inlineasm-ios.c
similarity index 100%
rename from clang/test/CodeGen/AArch64/inline-asm-ios.c
rename to clang/test/CodeGen/aarch64-inlineasm-ios.c

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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-08 Thread David Tellenbach via cfe-commits

dtellenbach wrote:

@MaskRay the added test fails since your commit 
https://github.com/llvm/llvm-project/commit/f4335f075b3496bce6b49f9267e6160d1824b1bb.
 The commit itself is alright, just exposed the underlying problem.

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


[clang] [llvm] [AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (PR #98097)

2024-07-08 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach created 
https://github.com/llvm/llvm-project/pull/98097

AArch64 uses MCAsmInfo::AssemblerDialect to control the style of emitted Neon 
assembly. E.g. Apple platforms use AsmWriterVariantTy::Apple by default which 
collides with InlineAsm::AD_Intel (both value 1). Checking for inlineasm 
dialects on non-X86 platforms can thus lead to problems.

>From 46e32d1156e38653c79682600fbf63d964277dba Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Mon, 8 Jul 2024 16:04:18 -0700
Subject: [PATCH] [AsmPrinter] Don't check for inlineasm dialect on non-X86
 platforms

AArch64 uses MCAsmInfo::AssemblerDialect to control the style of emitted
Neon assembly. E.g. Apple platforms use AsmWriterVariantTy::Apple by
default which collides with InlineAsm::AD_Intel (both value 1). Checking
for inlineasm dialects on non-X86 platforms can thus lead to problems.
---
 clang/test/CodeGen/AArch64/inline-asm-ios.c   | 23 +++
 .../AsmPrinter/AsmPrinterInlineAsm.cpp| 14 +++
 2 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/AArch64/inline-asm-ios.c

diff --git a/clang/test/CodeGen/AArch64/inline-asm-ios.c 
b/clang/test/CodeGen/AArch64/inline-asm-ios.c
new file mode 100644
index ..5e7328a15f69
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/inline-asm-ios.c
@@ -0,0 +1,23 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple arm64-apple-ios -S -o - %s | FileCheck %s
+
+// CHECK:   _restartable_function:
+// CHECK-NEXT: ldr x11, [x0]
+// CHECK-NEXT: add x11, x11, #1
+// CHECK-NEXT: str x11, [x0]
+// CHECK-NEXT:  Ltmp0:
+// CHECK-NEXT: b   Ltmp0
+// CHECK-NEXT:  LExit_restartable_function:
+// CHECK-NEXT: ret
+asm(".align 4\n"
+".text\n"
+".private_extern _restartable_function\n"
+"_restartable_function:\n"
+"ldrx11, [x0]\n"
+"addx11, x11, #1\n"
+"strx11, [x0]\n"
+"1:\n"
+"b 1b\n"
+"LExit_restartable_function:\n"
+"ret\n"
+);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 5a7013c964cb..6fe8d0e0af99 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -113,12 +113,16 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const 
MCSubtargetInfo &STI,
   if (!TAP)
 report_fatal_error("Inline asm not supported by this streamer because"
" we don't have an asm parser for this target\n");
-  Parser->setAssemblerDialect(Dialect);
+
+  // Respect inlineasm dialect on X86 targets only
+  if (TM.getTargetTriple().isX86()) {
+Parser->setAssemblerDialect(Dialect);
+// Enable lexing Masm binary and hex integer literals in intel inline
+// assembly.
+if (Dialect == InlineAsm::AD_Intel)
+  Parser->getLexer().setLexMasmIntegers(true);
+  }
   Parser->setTargetParser(*TAP);
-  // Enable lexing Masm binary and hex integer literals in intel inline
-  // assembly.
-  if (Dialect == InlineAsm::AD_Intel)
-Parser->getLexer().setLexMasmIntegers(true);
 
   emitInlineAsmStart();
   // Don't implicitly switch to the text section before the asm.

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


[clang] [clang][Apple][cmake] Disable plugin support at LLVM level (PR #89483)

2024-04-19 Thread David Tellenbach via cfe-commits

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

LGTM, thanks!

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


[clang] [clang][CodeCoverage] Fix conditional-operator test (PR #82192)

2024-02-18 Thread David Tellenbach via cfe-commits

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


[clang] [clang][CodeCoverage] Fix conditional-operator test (PR #82192)

2024-02-18 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach created 
https://github.com/llvm/llvm-project/pull/82192

None

>From 23b311470d4609fa394bc51b6fce8af83aeff022 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sun, 18 Feb 2024 14:46:43 -0800
Subject: [PATCH] [clang][CodeCoverage] Fix conditional-operator test

---
 clang/test/CoverageMapping/conditional-operator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 06b89c6b5a697e..956eb3d2aedac4 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -12,7 +12,7 @@ int binary_conditional(int x) {
 }
 
 // CHECK-LABEL:   ternary_conditional:
-// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits


@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {

dtellenbach wrote:

Ah, thanks for catching that!

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-18 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach updated 
https://github.com/llvm/llvm-project/pull/82141

>From f8e11fed8b4b6b0cc359e2915e4f2f32c3f08bb5 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sat, 17 Feb 2024 15:16:39 -0800
Subject: [PATCH 1/2] [clang][CodeCoverage] Fix CoverageMapping for binary
 conditionals ops

Fix an issue that produces a wrong coverage mapping when using binary
conditional operators as show in the example below.

Before this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}

After this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 ++
 .../CoverageMapping/conditional-operator.c| 25 +++
 2 files changed, 27 insertions(+)
 create mode 100644 clang/test/CoverageMapping/conditional-operator.c

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..5f3eb9c03e79fb
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}

>From 28737890db53bd2cef7a6fad4b260e20e325f899 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sun, 18 Feb 2024 14:28:58 -0800
Subject: [PATCH 2/2] Fix typo in test

---
 clang/test/CoverageMapping/conditional-operator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
index 5f3eb9c03e79fb..06b89c6b5a697e 100644
--- a/clang/test/CoverageMapping/conditional-operator.c
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -11,14 +11,14 @@ int binary_conditional(int x) {
   return y;
 }
 
-// CHECK-LABEL:   tenary_conditional:
+// CHECK-LABEL:   ternary_conditional:
 // CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
 // CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
 // CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
 // CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
 // CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
 // CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
-int tenary_conditional(int x) {
+int ternary_conditional(int x) {
   x = x ? x : 4;
   int y = x;
   return y;

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-17 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach created 
https://github.com/llvm/llvm-project/pull/82141

Fix an issue that produces a wrong coverage mapping when using binary 
conditional operators as show in the example below.

Before this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}
```

After this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
```

>From f8e11fed8b4b6b0cc359e2915e4f2f32c3f08bb5 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sat, 17 Feb 2024 15:16:39 -0800
Subject: [PATCH] [clang][CodeCoverage] Fix CoverageMapping for binary
 conditionals ops

Fix an issue that produces a wrong coverage mapping when using binary
conditional operators as show in the example below.

Before this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}

After this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 ++
 .../CoverageMapping/conditional-operator.c| 25 +++
 2 files changed, 27 insertions(+)
 create mode 100644 clang/test/CoverageMapping/conditional-operator.c

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..5f3eb9c03e79fb
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}

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


[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread David Tellenbach via cfe-commits

dtellenbach wrote:

> It should be fixed by 
> [56e205a](https://github.com/llvm/llvm-project/commit/56e205a89cbb114750f2bd3f5cfbd19e209d018a).

Thank you!

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


[clang] [compiler-rt] [llvm] [Profile] Refactor profile correlation. (PR #70856)

2023-11-01 Thread David Tellenbach via cfe-commits

dtellenbach wrote:

@ZequanWu this seems to cause issues on macOS: 
https://green.lab.llvm.org/green/job/clang-stage1-RA/36184/console
```
Profile-x86_64 :: Darwin/instrprof-debug-info-correlate.c
Profile-x86_64 :: instrprof-darwin-
Profile-x86_64h :: Darwin/instrprof-debug-info-correlate.c
Profile-x86_64h :: instrprof-darwin-exports.c
```
are failing, could you please take a look or revert?


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