[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-11-21 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D138846#4657195 , @zequanwu wrote:

> In D138846#4657194 , @alanphipps 
> wrote:
>
>> In D138846#4657193 , @zequanwu 
>> wrote:
>>
>>> In D138846#4657175 , @hans wrote:
>>>
 We're seeing crashes in `initializeValueProfRuntimeRecord` that bisects to 
 this commit. I think Zequan is investigating: 
 https://bugs.chromium.org/p/chromium/issues/detail?id=1503919
>>>
>>> It turns out to be that our rust code with old version of rustc without 
>>> this change, so mixture of raw profile versions are used, causing segment 
>>> fault.
>>
>> Thank you for the update! Is this also the case of the issue @glandium 
>> reports above as well?  I think both issues manifested as a ValueProf issue.
>
> I don't know, but I'd suggest to check if all sources compiled with profile 
> runtime are using the llvm version that contains this change. Otherwise, 
> mixed raw profiles versions will cause unexpected behaviour.

I just saw @glandium's earlier comment:

> Code built with older versions of LLVM (e.g. rust) and running with the 
> updated runtime crash at startup with this change.

This is the exact same issue we encountered. Because there is a profile format 
change, it's expected to update both clang and rustc to use the same version of 
llvm in order for it to work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-11-21 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D138846#4657194 , @alanphipps 
wrote:

> In D138846#4657193 , @zequanwu 
> wrote:
>
>> In D138846#4657175 , @hans wrote:
>>
>>> We're seeing crashes in `initializeValueProfRuntimeRecord` that bisects to 
>>> this commit. I think Zequan is investigating: 
>>> https://bugs.chromium.org/p/chromium/issues/detail?id=1503919
>>
>> It turns out to be that our rust code with old version of rustc without this 
>> change, so mixture of raw profile versions are used, causing segment fault.
>
> Thank you for the update! Is this also the case of the issue @glandium 
> reports above as well?  I think both issues manifested as a ValueProf issue.

I don't know, but I'd suggest to check if all sources compiled with profile 
runtime are using the llvm version that contains this change. Otherwise, mixed 
raw profiles versions will cause unexpected behaviour.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-11-21 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D138846#4657175 , @hans wrote:

> We're seeing crashes in `initializeValueProfRuntimeRecord` that bisects to 
> this commit. I think Zequan is investigating: 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1503919

It turns out to be that our rust code with old version of rustc without this 
change, so mixture of raw profile versions are used, causing segment fault.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-11-10 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:607
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not 
valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");

MaskRay wrote:
> Is this workaround still needed after 
> b0e61de7075942ef5ac8af9ca1ec918317f62152 (with a test 
> `clang/test/Coverage/unresolved-ctor-expr.cpp`)?
I think this workaround can be removed, verified it no longer crashes if 
reverting this change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

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


[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-10-02 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Hi, compiling llvm-10 code with this change causing compilation errors:

  
../../third_party/swiftshader/third_party/llvm-10.0/llvm/include/llvm/ADT/Optional.h:289:8:
 error: cannot overload a member function with ref-qualifier '&&' with a member 
function without a ref-qualifier
289 |   auto map(const Function ) &&
|^
  
../../third_party/swiftshader/third_party/llvm-10.0/llvm/include/llvm/ADT/Optional.h:272:8:
 note: previous declaration is here
272 |   auto map(const Function ) const
|^

Code snippet:

  template  class Optional {
  ...
template 
auto map(const Function ) &&
-> Optional {
  if (*this) return F(std::move(*this).getValue());
  return None;
}
  ...
  }

Is it intentional?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140828/new/

https://reviews.llvm.org/D140828

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157913#4648313 , @ellis wrote:

> I have seen that MachO sections remain in the header even if the size is zero 
> which seems to be the case here. You could use `llvm-objdump` to verify that 
> the section exists but the size is zero.

Thanks, I didn't notice that. And this can be easily detected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

I feel like either this feature not working well with mac or we should keep 
`__llvm_prf_names` section in the binary.

Current idea is to completely get rid of `__llvm_prf_names` section in the 
binary. Even if I fixed the issue https://reviews.llvm.org/D157913#4648296, 
llvm-cov will need to read information from 3 different places on mac: the 
binary (for `__llvm_cov_fun` and `__llvm_cov_map`), debug info (unused function 
names, which could live in `__llvm_prf_names`) and indexed profile file for 
(counter, data, instrumented function names). If we keep `__llvm_prf_names` in 
the binary, then llvm-cov doesn't need to look into debug info again.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu marked an inline comment as done.
zequanwu added a comment.

For some unknown reasons, linker still generates __llvm_prf_names section in 
the final binary on mac even if the object file doesn't have this section. And 
I cannot use llvm-objdump to get anything from that section.

  $ llvm-readelf -S ../tmp/a.out
  ...
Section {
  Index: 15
  Name: __llvm_prf_names (5F 5F 6C 6C 76 6D 5F 70 72 66 5F 6E 61 6D 65 73)
  Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
  Address: 0x100018000
  Size: 0x0
  Offset: 98304
  Alignment: 0
  RelocationOffset: 0x0
  RelocationCount: 0
  Type: Regular (0x0)
  Attributes [ (0x0)
  ]
  Reserved1: 0x0
  Reserved2: 0x0
  Reserved3: 0x0
}
  ...
  $ llvm-objdump --section=__llvm_prf_names --full-contents ../tmp/a.out
  ../tmp/a.out: file format mach-o arm64

I will delete the test for now as it's not working on mac: 
`compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu marked an inline comment as done.
zequanwu added inline comments.



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:42
+const char *InstrProfCorrelator::CovFunctionNameAttributeName =
+"Cov Function Name";
 

phosek wrote:
> I missed this earlier, but I think that spelling this out in full, that is 
> `Coverage Function Name`, would be more consistent with the `Coverage Type`.
Renamed at: 
https://github.com/llvm/llvm-project/commit/37402c34918a4627de77c3b20964207892383242


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157913#4646718 , @thakis wrote:

> Looks like this breaks check-clang on mac: 
> http://45.33.8.238/macm1/69297/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

https://github.com/llvm/llvm-project/commit/1f33bfc23fb9e94b4db75b1b18fd00a438446f51
 should fix it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-15 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32db121b29f7: [Coverage] Allow Clang coverage to be used 
with debug info correlation. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D157913?vs=556809=556869#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-profile-raw-version.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProfCorrelator.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfCorrelator.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll
  
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
@@ -0,0 +1,64 @@
+; Test if unused function names are correctly emitted as dwarf variable debug info under DW_TAG_compile_unit
+
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S > %t.ll
+; RUN: FileCheck < %t.ll --implicit-check-not "{{__llvm_prf_data|__llvm_prf_names}}" %s
+; RUN: %llc_dwarf -O0 -filetype=obj < %t.ll | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK-DWARF
+
+; REQUIRES: system-linux, object-emission
+
+@__profn_foo = private constant [3 x i8] c"foo"
+@__profn_bar = private constant [3 x i8] c"bar"
+@__profn_baz = private constant [3 x i8] c"baz"
+@__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz]
+; CHECK: @__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz], !dbg ![[DBG:[0-9]+]]
+; CHECK: ![[DBG]] = !DIGlobalVariableExpression(var: ![[VAR:[0-9]+]], expr: !DIExpression())
+; CHECK: ![[VAR]] = {{.*}} !DIGlobalVariable(name: "__llvm_coverage_names"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK: ![[SCOPE]] = {{.*}} !DICompileUnit(
+; CHECK: ![[ANNOTATIONS]] = !{![[FUNC_NAME1:[0-9]+]], ![[FUNC_NAME2:[0-9]+]]}
+; CHECK: ![[FUNC_NAME1]] = !{!"Cov Function Name", !"bar"}
+; CHECK: ![[FUNC_NAME2]] = !{!"Cov Function Name", !"baz"}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(ptr @__profn_foo, i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"branch-target-enforcement", i32 0}
+!6 = !{i32 8, !"sign-return-address", i32 0}
+!7 = !{i32 8, !"sign-return-address-all", i32 0}
+!8 = !{i32 8, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
+
+; CHECK-DWARF: DW_TAG_compile_unit
+; CHECK-DWARF:   DW_TAG_variable
+; CHECK-DWARF: DW_AT_name	("__llvm_coverage_names")
+; CHECK-DWARF: DW_AT_type	({{.*}} "Coverage Type")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("bar")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("baz")
+; CHECK-DWARF:   DW_TAG_unspecified_type
+; CHECK-DWARF: DW_AT_name ("Coverage Type")
+; CHECK-DWARF:   NULL
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- 

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157913#4646184 , @ellis wrote:

> It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
> intended?

I just moved 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll.` to 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll`
 and created a new test file 
`llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll.`




Comment at: compiler-rt/lib/profile/InstrProfilingWriter.c:276-277
   __llvm_profile_get_num_counters(CountersBegin, CountersEnd);
-  const uint64_t NamesSize = DebugInfoCorrelate ? 0 : NamesEnd - NamesBegin;
+  const uint64_t NamesSize =
+  DebugInfoCorrelate && IRLevelProfile ? 0 : NamesEnd - NamesBegin;
 

ellis wrote:
> Can we remove changes to this file now that we are stripping the names 
> section?
Reverted all changes in this file.



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:423
+  }
+  return;
+}

ellis wrote:
> I think this return should be on the line above to break out of the for loop 
> early. Or did I miscount the brackets?
Removed that if. It's already checked inside `IsDIEOfCovName`.



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:769
   }
+  if (DebugInfoCorrelate && !ReferencedNames.empty()) {
+MDNode *Node = *M->debug_compile_units_begin();

ellis wrote:
> Just so that I understand. Does this code run only for names of unused 
> functions? Or will we store all function names with 
> `CovFunctionNameAnnotation`?
Just the names of unused functions. All instrumented functions names will still 
be stored at the same place as before.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 556809.
zequanwu marked 3 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-profile-raw-version.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfCorrelator.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfCorrelator.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll
  
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
@@ -0,0 +1,66 @@
+; Test if unused function names are correctly emitted as dwarf variable debug info under DW_TAG_compile_unit
+
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S > %t.ll
+; RUN: FileCheck < %t.ll --implicit-check-not "{{__llvm_prf_data|__llvm_prf_names}}" %s
+; RUN: %llc_dwarf -O0 -filetype=obj < %t.ll | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK-DWARF
+
+; REQUIRES: system-linux, object-emission
+
+
+
+@__profn_foo = private constant [3 x i8] c"foo"
+@__profn_bar = private constant [3 x i8] c"bar"
+@__profn_baz = private constant [3 x i8] c"baz"
+@__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz]
+; CHECK: @__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz], !dbg ![[DBG:[0-9]+]]
+; CHECK: ![[DBG]] = !DIGlobalVariableExpression(var: ![[VAR:[0-9]+]], expr: !DIExpression())
+; CHECK: ![[VAR]] = {{.*}} !DIGlobalVariable(name: "__llvm_coverage_names"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK: ![[SCOPE]] = {{.*}} !DICompileUnit(
+; CHECK: ![[ANNOTATIONS]] = !{![[FUNC_NAME1:[0-9]+]], ![[FUNC_NAME2:[0-9]+]]}
+; CHECK: ![[FUNC_NAME1]] = !{!"Cov Function Name", !"bar"}
+; CHECK: ![[FUNC_NAME2]] = !{!"Cov Function Name", !"baz"}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(ptr @__profn_foo, i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"branch-target-enforcement", i32 0}
+!6 = !{i32 8, !"sign-return-address", i32 0}
+!7 = !{i32 8, !"sign-return-address-all", i32 0}
+!8 = !{i32 8, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
+
+; CHECK-DWARF: DW_TAG_compile_unit
+; CHECK-DWARF:   DW_TAG_variable
+; CHECK-DWARF: DW_AT_name	("__llvm_coverage_names")
+; CHECK-DWARF: DW_AT_type	({{.*}} "Coverage Type")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("bar")
+; CHECK-DWARF: DW_TAG_LLVM_annotation
+; CHECK-DWARF:   DW_AT_name	("Cov Function Name")
+; CHECK-DWARF:   DW_AT_const_value	("baz")
+; CHECK-DWARF:   DW_TAG_unspecified_type
+; CHECK-DWARF: DW_AT_name ("Coverage Type")
+; CHECK-DWARF:   NULL
Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
@@ -1,34 +0,0 @@
-; RUN: opt < %s -passes=instrprof 

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 556805.
zequanwu added a comment.

Remove profile name section.

Unused coverage function names are stored in debug info as a fake global 
variable info:

  0x000b: DW_TAG_compile_unit
  ...
  0x0071:   DW_TAG_variable
  DW_AT_name  ("__llvm_coverage_names")
  DW_AT_type  (0x0097 "Coverage Type")
  DW_AT_location  (DW_OP_addr 0x0)
  
  0x0084: DW_TAG_LLVM_annotation
DW_AT_name("Cov Function Name")
DW_AT_const_value ("bar")
  
  0x008d: DW_TAG_LLVM_annotation
DW_AT_name("Cov Function Name")
DW_AT_const_value ("baz")

llvm-cov will need to retrieve those names from the binary's debug info.

The reasons for not writing those names into the indexed profile file are 
following:

1. llvm-cov always need to read __llvm_covfun and __llvm_covmap from the 
unstripped binary, so it doesn't matter if those names are read from the binary 
or the indexed profile.
2. Since those names are just an array of strings, they don't have counter/data 
info. When llvm-profdata writes indexed profile, it iterates profile data to 
write records, so those unreferenced names are skipped even if I append them to 
the end of profile symtab. I'm not sure how we can simply append those names 
into the end of function name strings at indexed profile.

Overall, there are basically two types of function names:

1. Instrumented function names, which are stored in dwarf and later copied to 
indexed profile. llvm-cov reads them from indexed profile.
2. Unused function names(could be empty), which are stored in dwarf. llvm-cov 
reads them from the debug info.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-profile-raw-version.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfCorrelator.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfCorrelator.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll
  
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll
@@ -0,0 +1,66 @@
+; Test if unused function names are correctly emitted as dwarf variable debug info under DW_TAG_compile_unit
+
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S > %t.ll
+; RUN: FileCheck < %t.ll --implicit-check-not "{{__llvm_prf_data|__llvm_prf_names}}" %s
+; RUN: %llc_dwarf -O0 -filetype=obj < %t.ll | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK-DWARF
+
+; REQUIRES: system-linux, object-emission
+
+
+
+@__profn_foo = private constant [3 x i8] c"foo"
+@__profn_bar = private constant [3 x i8] c"bar"
+@__profn_baz = private constant [3 x i8] c"baz"
+@__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz]
+; CHECK: @__llvm_coverage_names = internal constant [2 x ptr] [ptr @__profn_bar, ptr @__profn_baz], !dbg ![[DBG:[0-9]+]]
+; CHECK: ![[DBG]] = !DIGlobalVariableExpression(var: ![[VAR:[0-9]+]], expr: !DIExpression())
+; CHECK: ![[VAR]] = {{.*}} !DIGlobalVariable(name: "__llvm_coverage_names"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK: ![[SCOPE]] = {{.*}} !DICompileUnit(
+; CHECK: ![[ANNOTATIONS]] = !{![[FUNC_NAME1:[0-9]+]], ![[FUNC_NAME2:[0-9]+]]}
+; CHECK: ![[FUNC_NAME1]] = !{!"Cov Function Name", !"bar"}
+; CHECK: ![[FUNC_NAME2]] = !{!"Cov Function Name", !"baz"}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(ptr @__profn_foo, i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", 

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157913#4638569 , @phosek wrote:

> In D157913#4626007 , @zequanwu 
> wrote:
>
>>> It seems that the `__llvm_prf_names` is retained in this mode. What is the 
>>> overhead of this section generally? Can we instead use debug info to lookup 
>>> function names?
>>
>> With debug info correlation enabled, `__llvm_prf_names` section will only 
>> contain functions names that are not emitted to the final binary, not even 
>> in debug info.
>
> Could we emit those names into the `.debug_str` section?

Yes, I think it's feasible by creating a fake variable debug info that contains 
all the skipped function names in the source file for each object file, but 
that's a bit more overhead in debug info compared to just plain 
`__llvm_prf_names` in binary, which is only about 0.2% or less of original size 
[1].

[1]: https://bugs.chromium.org/p/chromium/issues/detail?id=1463755#c8


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp:29
+
+// RUN: llvm-cov report --instr-profile=%t.profdata %t | FileCheck %s 
-check-prefix=NONAME
+

ellis wrote:
> Is it worth testing that `%t.normal.profdata` emits the same coverage?
Added testing for `%t.normal.profdata`.



Comment at: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp:1019-1029
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.isEmpty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)

ellis wrote:
> I don't quite understand why this was changed. Is there is a test case that 
> covers this?
This part of code is used by llvm-cov. Originally, it always checks if the 
instrumented binary contains the `__llvm_prf_names ` section and assumes all 
instrumented function names are store there. Now, it will firstly create 
`InstrProfSymtab` from the indexed profile file and add remaining function 
names to this `InstrProfSymtab` from `__llvm_prf_names` section in the 
instrumented binary, if there is one. 

This is covered by `// RUN: llvm-cov export --format=lcov 
--instr-profile=%t.profdata %t | FileCheck %s -check-prefix=NAME`, where 
`_Z9used_funcv` and `main` are stored in debug info and later moved to indexed 
profile file, and `_ZN1A11unused_funcEv` is stored in `__llvm_prf_names` 
section in the binary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 555889.
zequanwu marked 4 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-profile-raw-version.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp

Index: llvm/lib/ProfileData/InstrProfReader.cpp
===
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -574,8 +574,8 @@
   if (Correlator) {
 // These sizes in the raw file are zero because we constructed them in the
 // Correlator.
-assert(DataSize == 0 && NamesSize == 0);
-assert(CountersDelta == 0 && NamesDelta == 0);
+assert(DataSize == 0 && (!isIRLevelProfile() || NamesSize == 0));
+assert(CountersDelta == 0 && (!isIRLevelProfile() || NamesDelta == 0));
 Data = Correlator->getDataPointer();
 DataEnd = Data + Correlator->getDataSize();
 NamesStart = Correlator->getNamesPointer();
Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
@@ -981,7 +982,8 @@
 }
 
 static Expected>
-loadBinaryFormat(std::unique_ptr Bin, StringRef Arch,
+loadBinaryFormat(std::unique_ptr Bin,
+ IndexedInstrProfReader , StringRef Arch,
  StringRef CompilationDir = "",
  object::BuildIDRef *BinaryID = nullptr) {
   std::unique_ptr OF;
@@ -1010,11 +1012,21 @@
 
   // Look for the sections that we are interested in.
   auto ObjFormat = OF->getTripleObjectFormat();
+  InstrProfSymtab ProfileNames = ProfileReader.getSymtab();
   auto NamesSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
  /*AddSegmentInfo=*/false));
-  if (auto E = NamesSection.takeError())
-return std::move(E);
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.isEmpty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)
+  return make_error(coveragemap_error::malformed);
+if (Error E = ProfileNames.create(NamesSectionRefs.back()))
+  return std::move(E);
+  }
   auto CoverageSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
   /*AddSegmentInfo=*/false));
@@ -1028,13 +1040,6 @@
 return CoverageMappingOrErr.takeError();
   StringRef CoverageMapping = CoverageMappingOrErr.get();
 
-  InstrProfSymtab ProfileNames;
-  std::vector NamesSectionRefs = *NamesSection;
-  if (NamesSectionRefs.size() != 1)
-return make_error(coveragemap_error::malformed);
-  if (Error E = ProfileNames.create(NamesSectionRefs.back()))
-return std::move(E);
-
   // Look for the coverage records section (Version4 only).
   auto CoverageRecordsSections =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covfun, ObjFormat,
@@ -1104,7 +1109,8 @@
 
 Expected>>
 BinaryCoverageReader::create(
-MemoryBufferRef ObjectBuffer, StringRef Arch,
+MemoryBufferRef ObjectBuffer, IndexedInstrProfReader ,
+StringRef Arch,
 SmallVectorImpl> ,
 StringRef CompilationDir, SmallVectorImpl *BinaryIDs) {
   std::vector> Readers;
@@ -1150,8 +1156,8 @@
   }
 
   return BinaryCoverageReader::create(
-  ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
-  CompilationDir, BinaryIDs);
+  ArchiveOrErr.get()->getMemoryBufferRef(), ProfileReader, Arch,
+  ObjectFileBuffers, CompilationDir, BinaryIDs);
 }
   }
 
@@ -1164,8 +1170,8 @@
 return ChildBufOrErr.takeError();
 
   auto ChildReadersOrErr = BinaryCoverageReader::create(
-  ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
-  BinaryIDs);
+  ChildBufOrErr.get(), ProfileReader, Arch, ObjectFileBuffers,
+  CompilationDir, BinaryIDs);
   if 

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-08-29 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

> It seems that the `__llvm_prf_names` is retained in this mode. What is the 
> overhead of this section generally? Can we instead use debug info to lookup 
> function names?

With debug info correlation enabled, `__llvm_prf_names` section will only 
contain functions names that are not emitted to the final binary, not even in 
debug info. So, this section is still much smaller compared to when not 
enabling debug info correlation. This is used to indicate that those functions 
are covered but not executed.

Example from the test case above:

  $ cat a.cpp
  struct A {
void unused_func() {}
  };
  void used_func() {}
  int main() {
used_func();
return 0;
  }
  $ clang -fprofile-instr-generate -fcoverage-mapping -mllvm 
-enable-name-compression=false -mllvm -debug-info-correlate -g a.cpp -o a.out
  $ llvm-objdump --section=__llvm_prf_names --full-contents a.out
  
  a.out:  file format elf64-x86-64
  Contents of section __llvm_prf_names:
   7b65 14005f5a 4e314131 31756e75 7365645f  .._ZN1A11unused_
   7b75 66756e63 4576funcEv


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [WIP][Coverage] Allow Clang coverage to be used with debug info correlation.

2023-08-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 554048.
zequanwu added a comment.

__llvm_prf_names section in the binary could be non-zero because 
non-instrumented function names are store there to indicate execution of 0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-debug-info-correlate.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp

Index: llvm/lib/ProfileData/InstrProfReader.cpp
===
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -574,8 +574,8 @@
   if (Correlator) {
 // These sizes in the raw file are zero because we constructed them in the
 // Correlator.
-assert(DataSize == 0 && NamesSize == 0);
-assert(CountersDelta == 0 && NamesDelta == 0);
+assert(DataSize == 0 && (!isIRLevelProfile() || NamesSize == 0));
+assert(CountersDelta == 0 && (!isIRLevelProfile() || NamesDelta == 0));
 Data = Correlator->getDataPointer();
 DataEnd = Data + Correlator->getDataSize();
 NamesStart = Correlator->getNamesPointer();
Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
@@ -981,7 +982,8 @@
 }
 
 static Expected>
-loadBinaryFormat(std::unique_ptr Bin, StringRef Arch,
+loadBinaryFormat(std::unique_ptr Bin,
+ IndexedInstrProfReader , StringRef Arch,
  StringRef CompilationDir = "",
  object::BuildIDRef *BinaryID = nullptr) {
   std::unique_ptr OF;
@@ -1010,11 +1012,21 @@
 
   // Look for the sections that we are interested in.
   auto ObjFormat = OF->getTripleObjectFormat();
+  InstrProfSymtab ProfileNames = ProfileReader.getSymtab();
   auto NamesSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
  /*AddSegmentInfo=*/false));
-  if (auto E = NamesSection.takeError())
-return std::move(E);
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.isEmpty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)
+  return make_error(coveragemap_error::malformed);
+if (Error E = ProfileNames.create(NamesSectionRefs.back()))
+  return std::move(E);
+  }
   auto CoverageSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
   /*AddSegmentInfo=*/false));
@@ -1028,13 +1040,6 @@
 return CoverageMappingOrErr.takeError();
   StringRef CoverageMapping = CoverageMappingOrErr.get();
 
-  InstrProfSymtab ProfileNames;
-  std::vector NamesSectionRefs = *NamesSection;
-  if (NamesSectionRefs.size() != 1)
-return make_error(coveragemap_error::malformed);
-  if (Error E = ProfileNames.create(NamesSectionRefs.back()))
-return std::move(E);
-
   // Look for the coverage records section (Version4 only).
   auto CoverageRecordsSections =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covfun, ObjFormat,
@@ -1104,7 +1109,8 @@
 
 Expected>>
 BinaryCoverageReader::create(
-MemoryBufferRef ObjectBuffer, StringRef Arch,
+MemoryBufferRef ObjectBuffer, IndexedInstrProfReader ,
+StringRef Arch,
 SmallVectorImpl> ,
 StringRef CompilationDir, SmallVectorImpl *BinaryIDs) {
   std::vector> Readers;
@@ -1150,8 +1156,8 @@
   }
 
   return BinaryCoverageReader::create(
-  ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
-  CompilationDir, BinaryIDs);
+  ArchiveOrErr.get()->getMemoryBufferRef(), ProfileReader, Arch,
+  ObjectFileBuffers, CompilationDir, BinaryIDs);
 }
   }
 
@@ -1164,8 +1170,8 @@
 return ChildBufOrErr.takeError();
 
   auto ChildReadersOrErr = BinaryCoverageReader::create(
-  ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
-  BinaryIDs);
+  ChildBufOrErr.get(), 

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-28 Thread Zequan Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf52f8e817ea3: [Profile] Allow online merging with debug info 
correlation. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D157632?vs=550051=554035#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-empty-data.test
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/instrprof-merge-empty-data.test
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-merge-empty-data.test
@@ -0,0 +1,14 @@
+// Test online merging with empty data section.
+// RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir
+// RUN: %clangxx_profgen -fcoverage-mapping -o %t main.c -fprofile-list=funlist
+// RUN: env LLVM_PROFILE_FILE='a%m.profraw' %t
+// RUN: env LLVM_PROFILE_FILE='a%m.profraw' %t 2>&1 | FileCheck %s --allow-empty
+
+// CHECK-NOT: LLVM Profile Error
+
+//--- main.c
+int main() {}
+
+//--- funlist
+[clang]
+default:skip
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show 

[PATCH] D126586: [InstrProf] Single byte counters in coverage

2023-08-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:4812
+} else
+  CGF.incrementProfileCounter(E);
+  }

This can be hoist outside `if (llvm::EnableSingleByteCoverage)`



Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:1080-1081
+void CodeGenPGO::setProfileVersion(llvm::Module ) {
+  if (CGM.getCodeGenOpts().hasProfileClangInstr() &&
+  llvm::EnableSingleByteCoverage) {
+const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));

I thinkit's better to emit the profile version global variable in 
`CoverageMappingModuleGen::emit` so this check 
`CGM.getCodeGenOpts().hasProfileClangInstr()` is not necessary. 

Also we should always emit the profile version global variable so that the 
runtime/backend knows if single byte coverage is enabled or not by looking at 
the version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126586/new/

https://reviews.llvm.org/D126586

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


[PATCH] D159000: Reland "[Profile] Allow online merging with debug info correlation."

2023-08-28 Thread Zequan Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
zequanwu marked an inline comment as done.
Closed by commit rGd80992032fd0: Reland [Profile] Allow online merging 
with debug info correlation. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D159000?vs=553956=553988#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159000/new/

https://reviews.llvm.org/D159000

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-empty-data.test
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/instrprof-merge-empty-data.test
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-merge-empty-data.test
@@ -0,0 +1,14 @@
+// Test online merging with empty data section.
+// RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir
+// RUN: %clangxx_profgen -fcoverage-mapping -o %t main.c -fprofile-list=funlist
+// RUN: LLVM_PROFILE_FILE='a%m.profraw' %t
+// RUN: LLVM_PROFILE_FILE='a%m.profraw' %t 2>&1 | FileCheck %s --allow-empty
+
+// CHECK-NOT: LLVM Profile Error
+
+//--- main.c
+int main() {}
+
+//--- funlist
+[clang]
+default:skip
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions 

[PATCH] D159000: Reland "[Profile] Allow online merging with debug info correlation."

2023-08-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: ellis, aeubanks.
Herald added subscribers: Enna1, ormris.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Fixed the issue when data is 0 by relaxing the condition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159000

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-empty-data.test
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/instrprof-merge-empty-data.test
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-merge-empty-data.test
@@ -0,0 +1,14 @@
+// Test 
+// RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir
+// RUN: %clangxx_profgen -fcoverage-mapping -o %t main.c -fprofile-list=funlist
+// RUN: LLVM_PROFILE_FILE='a%m.profraw' %t
+// RUN: LLVM_PROFILE_FILE='a%m.profraw' %t 2>&1 | FileCheck %s --allow-empty
+
+// CHECK-NOT: LLVM Profile Error
+
+//--- main.c
+int main() {}
+
+//--- funlist
+[clang]
+default:skip
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// 

[PATCH] D157913: [WIP][Coverage] Allow Clang coverage to be used with debug info correlation.

2023-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 551219.
zequanwu added a comment.

Update.
Binary may still contains __llvm_prf_names sections for functions that are not 
emitted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-debug-info-correlate.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.c
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.c
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
@@ -953,7 +954,8 @@
 }
 
 static Expected>
-loadBinaryFormat(std::unique_ptr Bin, StringRef Arch,
+loadBinaryFormat(std::unique_ptr Bin,
+ IndexedInstrProfReader , StringRef Arch,
  StringRef CompilationDir = "",
  object::BuildIDRef *BinaryID = nullptr) {
   std::unique_ptr OF;
@@ -982,11 +984,21 @@
 
   // Look for the sections that we are interested in.
   auto ObjFormat = OF->getTripleObjectFormat();
+  InstrProfSymtab ProfileNames = ProfileReader.getSymtab();
   auto NamesSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
  /*AddSegmentInfo=*/false));
-  if (auto E = NamesSection.takeError())
-return std::move(E);
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.getNameData().empty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)
+  return make_error(coveragemap_error::malformed);
+if (Error E = ProfileNames.create(NamesSectionRefs.back()))
+  return std::move(E);
+  }
   auto CoverageSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
   /*AddSegmentInfo=*/false));
@@ -1000,13 +1012,6 @@
 return CoverageMappingOrErr.takeError();
   StringRef CoverageMapping = CoverageMappingOrErr.get();
 
-  InstrProfSymtab ProfileNames;
-  std::vector NamesSectionRefs = *NamesSection;
-  if (NamesSectionRefs.size() != 1)
-return make_error(coveragemap_error::malformed);
-  if (Error E = ProfileNames.create(NamesSectionRefs.back()))
-return std::move(E);
-
   // Look for the coverage records section (Version4 only).
   auto CoverageRecordsSections =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covfun, ObjFormat,
@@ -1076,7 +1081,8 @@
 
 Expected>>
 BinaryCoverageReader::create(
-MemoryBufferRef ObjectBuffer, StringRef Arch,
+MemoryBufferRef ObjectBuffer, IndexedInstrProfReader ,
+StringRef Arch,
 SmallVectorImpl> ,
 StringRef CompilationDir, SmallVectorImpl *BinaryIDs) {
   std::vector> Readers;
@@ -1117,8 +1123,8 @@
   }
 
   return BinaryCoverageReader::create(
-  ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
-  CompilationDir, BinaryIDs);
+  ArchiveOrErr.get()->getMemoryBufferRef(), ProfileReader, Arch,
+  ObjectFileBuffers, CompilationDir, BinaryIDs);
 }
   }
 
@@ -1131,8 +1137,8 @@
 return ChildBufOrErr.takeError();
 
   auto ChildReadersOrErr = BinaryCoverageReader::create(
-  ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
-  BinaryIDs);
+  ChildBufOrErr.get(), ProfileReader, Arch, ObjectFileBuffers,
+  CompilationDir, BinaryIDs);
   if (!ChildReadersOrErr)
 return ChildReadersOrErr.takeError();
   for (auto  : ChildReadersOrErr.get())
@@ -1152,8 +1158,9 @@
   }
 
   object::BuildIDRef BinaryID;
-  auto ReaderOrErr = loadBinaryFormat(std::move(Bin), Arch, CompilationDir,
-  BinaryIDs ?  : nullptr);
+  auto ReaderOrErr =
+  loadBinaryFormat(std::move(Bin), ProfileReader, Arch, CompilationDir,
+   BinaryIDs ?  : nullptr);
   if (!ReaderOrErr)
 return ReaderOrErr.takeError();
   Readers.push_back(std::move(ReaderOrErr.get()));
Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -360,7 +360,7 @@
 
  

[PATCH] D157913: [WIP][Coverage] Allow Clang coverage to be used with debug info correlation.

2023-08-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Debug info correlation is an option in InstrProfiling pass, which is used by
both IR instrumentation and front-end instrumentation. So, Clang coverage can
also benefits the binary size saving from it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157913

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CodeGen/coverage-debug-info-correlate.c
  compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.c
  compiler-rt/test/profile/Linux/coverage-debug-info-correlate.c
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
@@ -953,7 +954,8 @@
 }
 
 static Expected>
-loadBinaryFormat(std::unique_ptr Bin, StringRef Arch,
+loadBinaryFormat(std::unique_ptr Bin,
+ IndexedInstrProfReader , StringRef Arch,
  StringRef CompilationDir = "",
  object::BuildIDRef *BinaryID = nullptr) {
   std::unique_ptr OF;
@@ -982,11 +984,20 @@
 
   // Look for the sections that we are interested in.
   auto ObjFormat = OF->getTripleObjectFormat();
+  InstrProfSymtab ProfileNames;
   auto NamesSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
  /*AddSegmentInfo=*/false));
-  if (auto E = NamesSection.takeError())
-return std::move(E);
+  if (auto E = NamesSection.takeError()) {
+consumeError(std::move(E));
+ProfileNames = ProfileReader.getSymtab();
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)
+  return make_error(coveragemap_error::malformed);
+if (Error E = ProfileNames.create(NamesSectionRefs.back()))
+  return std::move(E);
+  }
   auto CoverageSection =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
   /*AddSegmentInfo=*/false));
@@ -1000,13 +1011,6 @@
 return CoverageMappingOrErr.takeError();
   StringRef CoverageMapping = CoverageMappingOrErr.get();
 
-  InstrProfSymtab ProfileNames;
-  std::vector NamesSectionRefs = *NamesSection;
-  if (NamesSectionRefs.size() != 1)
-return make_error(coveragemap_error::malformed);
-  if (Error E = ProfileNames.create(NamesSectionRefs.back()))
-return std::move(E);
-
   // Look for the coverage records section (Version4 only).
   auto CoverageRecordsSections =
   lookupSections(*OF, getInstrProfSectionName(IPSK_covfun, ObjFormat,
@@ -1076,7 +1080,8 @@
 
 Expected>>
 BinaryCoverageReader::create(
-MemoryBufferRef ObjectBuffer, StringRef Arch,
+MemoryBufferRef ObjectBuffer, IndexedInstrProfReader ,
+StringRef Arch,
 SmallVectorImpl> ,
 StringRef CompilationDir, SmallVectorImpl *BinaryIDs) {
   std::vector> Readers;
@@ -1117,8 +1122,8 @@
   }
 
   return BinaryCoverageReader::create(
-  ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
-  CompilationDir, BinaryIDs);
+  ArchiveOrErr.get()->getMemoryBufferRef(), ProfileReader, Arch,
+  ObjectFileBuffers, CompilationDir, BinaryIDs);
 }
   }
 
@@ -1131,8 +1136,8 @@
 return ChildBufOrErr.takeError();
 
   auto ChildReadersOrErr = BinaryCoverageReader::create(
-  ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
-  BinaryIDs);
+  ChildBufOrErr.get(), ProfileReader, Arch, ObjectFileBuffers,
+  CompilationDir, BinaryIDs);
   if (!ChildReadersOrErr)
 return ChildReadersOrErr.takeError();
   for (auto  : ChildReadersOrErr.get())
@@ -1152,8 +1157,9 @@
   }
 
   object::BuildIDRef BinaryID;
-  auto ReaderOrErr = loadBinaryFormat(std::move(Bin), Arch, CompilationDir,
-  BinaryIDs ?  : nullptr);
+  auto ReaderOrErr =
+  loadBinaryFormat(std::move(Bin), ProfileReader, Arch, CompilationDir,
+   BinaryIDs ?  : nullptr);
   if (!ReaderOrErr)
 return ReaderOrErr.takeError();
   Readers.push_back(std::move(ReaderOrErr.get()));
Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-14 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf2cf195d5fb: [Profile] Allow online merging with debug info 
correlation. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/lib/profile/InstrProfilingMerge.c
===
--- compiler-rt/lib/profile/InstrProfilingMerge.c
+++ compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -47,13 +47,16 @@
 COMPILER_RT_VISIBILITY
 int 

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 550039.
zequanwu marked 3 inline comments as done.
zequanwu added a comment.

Rebase and address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,23 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov.dSYM %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
Index: compiler-rt/lib/profile/InstrProfilingMerge.c
===
--- compiler-rt/lib/profile/InstrProfilingMerge.c
+++ compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -47,13 +47,16 @@
 COMPILER_RT_VISIBILITY
 int __llvm_profile_check_compatibility(const char *ProfileData,

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157632#4581219 , @ellis wrote:

> In D157632#4580576 , @zequanwu 
> wrote:
>
>> BTW, I noticed something strange with `-pgo-function-entry-coverage` when 
>> merging via llvm-profdata.
>
> This is intentional. The two raw profiles individually store blocks as either 
> covered or not, but when we merge them they get converted to counters and 
> accumulated.
> https://github.com/llvm/llvm-project/blob/6a0feb1503e21432e63d93b44357bad43f8026d1/llvm/lib/ProfileData/InstrProf.cpp#L726
> Then in `PGOUseFunc::populateCoverage()` we annotate blocks as alive if their 
> counter value is non-zero.
> https://github.com/llvm/llvm-project/blob/1aee2434ce4c9b5785cbc8f72cbbbd64f9e85297/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp#L1399
> My logic was that the indexed profile represents these counters as ints, so 
> we might as well accumulate them. Also, this makes the implementation simpler.

Thanks for explanation. That makes sense.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

BTW, I noticed something strange with `-pgo-function-entry-coverage` when 
merging via llvm-profdata.
In this file `compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c`, 
I ran the following:

  // RUN: %clang_pgogen -o %t.cov.normal -mllvm --pgo-function-entry-coverage 
-mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
  // RUN: rm -rf %t.dir && mkdir %t.dir
  // RUN: env LLVM_PROFILE_FILE=%t.dir/%m.profraw %run %t.cov.normal
  // RUN: env LLVM_PROFILE_FILE=%t.dir/%m.profraw %run %t.cov.normal
  // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.dir/
  // RUN: llvm-profdata show --all-functions --counts %t.cov.normal.profdata
  // It shows block counts 1.
  Counters:
main:
  Hash: 0x06d15c67b2c35b9c
  Counters: 1
  Block counts: [1]
_Z3fooi:
  Hash: 0x0209aa3e3852da94
  Counters: 1
  Block counts: [1]
_Z3bari:
  Hash: 0x0209aa3e1d398548
  Counters: 1
  Block counts: [1]
_Z6unusedi:
  Hash: 0x0a4d0ad3efff
  Counters: 1
  Block counts: [0]
  Instrumentation level: IR  entry_first = 0
  Functions shown: 4
  Total functions: 4
  Maximum function count: 1
  Maximum internal block count: 0
  
  // RUN: rm -rf %t.dir && mkdir %t.dir
  // RUN: env LLVM_PROFILE_FILE=%t.dir/%t.cov-1.profraw %run %t.cov.normal
  // RUN: env LLVM_PROFILE_FILE=%t.dir/%t.cov-2.profraw %run %t.cov.normal
  // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.dir/
  // RUN: llvm-profdata show --all-functions --counts %t.cov.normal.profdata
  // It shows block counts 2, as opposed to 1.
  Counters:
main:
  Hash: 0x06d15c67b2c35b9c
  Counters: 1
  Block counts: [2]
_Z3fooi:
  Hash: 0x0209aa3e3852da94
  Counters: 1
  Block counts: [2]
_Z3bari:
  Hash: 0x0209aa3e1d398548
  Counters: 1
  Block counts: [2]
_Z6unusedi:
  Hash: 0x0a4d0ad3efff
  Counters: 1
  Block counts: [0]
  Instrumentation level: IR  entry_first = 0
  Functions shown: 4
  Total functions: 4
  Maximum function count: 2
  Maximum internal block count: 0


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D157632#4578582 , @ellis wrote:

> I've just published https://reviews.llvm.org/D157664, so you'll want to 
> rebase ontop of it if it lands soon. I would also like to see some more tests 
> added to `instrprof-merge-error.c` to make sure two different binaries can't 
> merge profiles together with `--debug-info-correlate`. I was thinking the 
> test would be something like this.
>
>   // RUN: %clang_pgogen -o %t/a -g -mllvm --debug-info-correlate -mllvm 
> --disable-vp=true %t/main.c
>   // RUN: %clang_pgogen -o %t/b -g -mllvm --debug-info-correlate -mllvm 
> --disable-vp=true %t/main.c %t/foo.c
>   // RUN: env LLVM_PROFILE_FILE=%t/default_%m.profdata %run %t/a
>   // This next line should fail to merge because the counter sections have 
> different sizes
>   // RUN: env LLVM_PROFILE_FILE=%t/default_%m.profdata %run %t/b
>   
>   //--- main.c
>   int main() { return 0; }
>   //--- foo.c
>   int foo() { return 4; }

In this example, `%m` will translated to two different values so they won't be 
merged. As I mentioned in the inline comment, 
`__llvm_profile_check_compatibility` will verify that for us.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:129
+  // enabled.
+  if (Header->DataSize == 0) {
+if (!(__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE)) {

ellis wrote:
> Since we don't have the data section, we need to be confident that existing 
> profile comes from the same binary (so that the counter section is 
> identical). Can we add some extra checks here? I'm thinking we can verify 
> that some fields in the headers match and that the variant flags are 
> identical.
The [[ 
https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfiling.h#L105-L107
 | comment ]] says the caller of this function is responsible for the check. 
And we [[ 
https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingMerge.c#L48
 | verifies ]] that fields in both headers math before merging at 
doProfileMerging.



Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:134-136
+for (SrcCounter = SrcCountersStart,
+DstCounter = __llvm_profile_begin_counters();
+ SrcCounter < SrcCountersEnd;) {

ellis wrote:
> Can you add a check to make sure src and dst have the same number of counters 
> (`SrcCountersEnd - SrcCountersStart`)?
Added the check at `__llvm_profile_check_compatibility`. 

I use in-memory `__llvm_profile_counter_entry_size()` to calculate in-file 
SrcCountersEnd, because the header only tells number of counters.



Comment at: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c:26
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/

ellis wrote:
> We need to run this line twice to correctly test 
> `__llvm_profile_merge_from_buffer()`
Added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 549424.
zequanwu marked 3 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/instrprof-merge-error.c

Index: compiler-rt/test/profile/instrprof-merge-error.c
===
--- compiler-rt/test/profile/instrprof-merge-error.c
+++ compiler-rt/test/profile/instrprof-merge-error.c
@@ -1,11 +1,5 @@
 // RUN: rm -rf %t; mkdir %t
 
-// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
-// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG
-
-// DBG: Debug info correlation does not support profile merging at runtime.
-
 // RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
 // RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF
Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,29 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show %t.cov.normal.profdata) <(llvm-profdata show %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
+// RUN: diff %t.normal.profdata %t.profdata
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts %t.cov.profdata)
+// RUN: diff %t.cov.normal.profdata %t.cov.profdata
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,27 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff %t.cov.normal.profdata %t.cov.profdata
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+
+// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t.normal
+// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t-1.profraw %t-2.profraw
+
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff %t.normal.profdata %t.profdata
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env 

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-10 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 549077.
zequanwu added a comment.

Remove debug includes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c

Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,19 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show %t.cov.normal.profdata) <(llvm-profdata show %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show %t.normal.profdata) <(llvm-profdata show %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show %t.cov.normal.profdata) <(llvm-profdata show %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,19 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff %t.cov.normal.profdata %t.cov.profdata
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff %t.normal.profdata %t.profdata
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov.dSYM %t.profdir/
+
+// RUN: diff %t.cov.normal.profdata %t.cov.profdata
Index: compiler-rt/lib/profile/InstrProfilingMerge.c
===
--- compiler-rt/lib/profile/InstrProfilingMerge.c
+++ compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -102,17 +102,10 @@
 COMPILER_RT_VISIBILITY
 int __llvm_profile_merge_from_buffer(const char *ProfileData,
  uint64_t ProfileSize) {
-  if (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) {
-PROF_ERR(
-"%s\n",
-"Debug info correlation does not support profile merging at runtime. "
-"Instead, merge raw profiles using the llvm-profdata tool.");
-return 1;
-  }
-
   __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;
   __llvm_profile_header *Header = (__llvm_profile_header *)ProfileData;
-  char *SrcCountersStart;
+  char *SrcCountersStart, *DstCounter;
+  const char *SrcCountersEnd, *SrcCounter;
   const char *SrcNameStart;
   const char *SrcValueProfDataStart, *SrcValueProfData;
   uintptr_t CountersDelta = Header->CountersDelta;
@@ -122,14 +115,36 @@
   Header->BinaryIdsSize);
   SrcDataEnd = SrcDataStart + Header->DataSize;
   SrcCountersStart = (char *)SrcDataEnd;
-  SrcNameStart = SrcCountersStart +
- Header->CountersSize * __llvm_profile_counter_entry_size();
+  SrcCountersEnd = SrcCountersStart +
+ Header->CountersSize * __llvm_profile_counter_entry_size(); 
+  SrcNameStart = SrcCountersEnd;
   SrcValueProfDataStart =
   SrcNameStart + Header->NamesSize +
   __llvm_profile_get_num_padding_bytes(Header->NamesSize);
   

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-10 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: ellis, MaskRay, davidxl.
Herald added subscribers: Enna1, ormris.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

When using debug info correlation, value profiling needs to be switched off.
So, we are only merging counter sections. In that case the existance of data
section is just used to provide an extra check in case of corrupted profile.

This patch performs counter merging by iterating the counter section by counter
size and add them together.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157632

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
  compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c

Index: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -24,3 +24,19 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff <(llvm-profdata show %t.cov.normal.profdata) <(llvm-profdata show %t.cov.profdata)
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.profdir/
+
+// RUN: diff <(llvm-profdata show %t.normal.profdata) <(llvm-profdata show %t.profdata)
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.profdir/
+
+// RUN: diff <(llvm-profdata show %t.cov.normal.profdata) <(llvm-profdata show %t.cov.profdata)
Index: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
===
--- compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -18,3 +18,19 @@
 // RUN: llvm-profdata merge -o %t.cov.normal.profdata %t.cov.profraw
 
 // RUN: diff %t.cov.normal.profdata %t.cov.profdata
+
+// Test debug info correlate with online merging.
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/
+
+// RUN: diff %t.normal.profdata %t.profdata
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m.cov.proflite %run %t.cov
+// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov.dSYM %t.profdir/
+
+// RUN: diff %t.cov.normal.profdata %t.cov.profdata
Index: compiler-rt/lib/profile/InstrProfilingMerge.c
===
--- compiler-rt/lib/profile/InstrProfilingMerge.c
+++ compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -1,3 +1,4 @@
+#include "/tmp/debug.h"
 /*===- InstrProfilingMerge.c - Profile in-process Merging  ---===*\
 |*
 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -11,6 +12,7 @@
 
 #include "InstrProfiling.h"
 #include "InstrProfilingInternal.h"
+#include "InstrProfilingPort.h"
 #include "InstrProfilingUtil.h"
 
 #define INSTR_PROF_VALUE_PROF_DATA
@@ -102,17 +104,10 @@
 COMPILER_RT_VISIBILITY
 int __llvm_profile_merge_from_buffer(const char *ProfileData,
  uint64_t ProfileSize) {
-  if (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) {
-PROF_ERR(
-"%s\n",
-"Debug info correlation does not support profile merging at runtime. "
-"Instead, merge raw profiles using the llvm-profdata tool.");
-return 1;
-  }
-
   __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;
   __llvm_profile_header 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D152472#4425713 , @thakis wrote:

> This is still breaking check-clang on windows: 
> http://45.33.8.238/win/79908/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

Sorry, I thought I applied the fix, but that was on another machine. The 
actually fix is in 
https://reviews.llvm.org/rG9d910b1073198716f85e5a7e7e9c8fd1f24d4c60.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

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


[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D152472#4423160 , @thakis wrote:

> Also on http://45.33.8.238/win/79874/step_7.txt
>
> Reverted in 9c560350dd57d0dcb849c5915fa7c50b139ce671 
>  for now.

Thanks for reporting. Relanded at 
https://reviews.llvm.org/rG879e88693338657aec092db749ddfcb582c65491 with fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

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


[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d54213ee557: [Clang][MS] Remove assertion on BaseOffset 
cant be smaller than Size. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

Files:
  clang/include/clang/Frontend/LayoutOverrideSource.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Frontend/LayoutOverrideSource.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
  clang/test/CodeGenCXX/override-layout-ms.cpp

Index: clang/test/CodeGenCXX/override-layout-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/override-layout-ms.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-ms.layout %s | FileCheck  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts %s | FileCheck  %s
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E1 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Mid
+// CHECK:  0 |   void * p
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E2 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine
+// CHECK:  0 |   struct E1 (base) (empty)
+// CHECK:  0 |   struct Mid (base)
+// CHECK:  0 | void * p
+// CHECK:  0 |   struct E2 (base) (empty)
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine2
+// CHECK:  0 |   struct VB1 (primary base)
+// CHECK:  0 | (VB1 vftable pointer)
+// CHECK:  8 |   struct VB2 (base)
+// CHECK:  8 | (VB2 vftable pointer)
+// CHECK:| [sizeof=16, align=8,
+// CHECK:|  nvsize=16, nvalign=8]
+
+
+struct E1 {};
+struct E2 {};
+struct Mid {void *p; };
+struct __declspec(empty_bases) Combine : E1, Mid, E2 {};
+struct VB1 { virtual void foo() {}};
+struct VB2 { virtual void bar() {}};
+struct Combine2: VB1, VB2 {};
+Combine g;
+Combine2 f;
\ No newline at end of file
Index: clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
@@ -0,0 +1,49 @@
+*** Dumping AST Record Layout
+Type: struct E1
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Mid
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: [0]>
+
+*** Dumping AST Record Layout
+Type: struct E2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
Index: clang/lib/Frontend/LayoutOverrideSource.cpp
===
--- clang/lib/Frontend/LayoutOverrideSource.cpp
+++ clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,18 @@
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  (void)S.substr(0, Idx).getAsInteger(10, ULL);
+  S = S.substr(Idx);
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +93,8 @@
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +105,13 @@
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  (void)LineStr.getAsInteger(10, Alignment);
-  CurrentLayout.Align = 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 531438.
zequanwu marked 5 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

Files:
  clang/include/clang/Frontend/LayoutOverrideSource.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Frontend/LayoutOverrideSource.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
  clang/test/CodeGenCXX/override-layout-ms.cpp

Index: clang/test/CodeGenCXX/override-layout-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/override-layout-ms.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-ms.layout %s | FileCheck  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts %s | FileCheck  %s
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E1 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Mid
+// CHECK:  0 |   void * p
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E2 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine
+// CHECK:  0 |   struct E1 (base) (empty)
+// CHECK:  0 |   struct Mid (base)
+// CHECK:  0 | void * p
+// CHECK:  0 |   struct E2 (base) (empty)
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine2
+// CHECK:  0 |   struct VB1 (primary base)
+// CHECK:  0 | (VB1 vftable pointer)
+// CHECK:  8 |   struct VB2 (base)
+// CHECK:  8 | (VB2 vftable pointer)
+// CHECK:| [sizeof=16, align=8,
+// CHECK:|  nvsize=16, nvalign=8]
+
+
+struct E1 {};
+struct E2 {};
+struct Mid {void *p; };
+struct __declspec(empty_bases) Combine : E1, Mid, E2 {};
+struct VB1 { virtual void foo() {}};
+struct VB2 { virtual void bar() {}};
+struct Combine2: VB1, VB2 {};
+Combine g;
+Combine2 f;
\ No newline at end of file
Index: clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
@@ -0,0 +1,49 @@
+*** Dumping AST Record Layout
+Type: struct E1
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Mid
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: [0]>
+
+*** Dumping AST Record Layout
+Type: struct E2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
Index: clang/lib/Frontend/LayoutOverrideSource.cpp
===
--- clang/lib/Frontend/LayoutOverrideSource.cpp
+++ clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,18 @@
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  (void)S.substr(0, Idx).getAsInteger(10, ULL);
+  S = S.substr(Idx);
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +93,8 @@
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +105,13 @@
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  (void)LineStr.getAsInteger(10, Alignment);
-  CurrentLayout.Align = Alignment;
+  if (parseUnsigned(LineStr, Alignment))
+CurrentLayout.Align = Alignment;
   continue;
 }
 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-08 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 529757.
zequanwu added a comment.
Herald added subscribers: ChuanqiXu, mgrang.

Extend the output and reading of -fdump-record-layouts-simple.
Add a test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152472/new/

https://reviews.llvm.org/D152472

Files:
  clang/include/clang/Frontend/LayoutOverrideSource.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Frontend/LayoutOverrideSource.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
  clang/test/CodeGenCXX/override-layout-ms.cpp

Index: clang/test/CodeGenCXX/override-layout-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/override-layout-ms.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-ms.layout %s | FileCheck  %s
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E1 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Mid
+// CHECK:  0 |   void * p
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct E2 (empty)
+// CHECK:| [sizeof=1, align=1,
+// CHECK:|  nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK:  0 | struct Combine
+// CHECK:  0 |   struct E1 (base) (empty)
+// CHECK:  0 |   struct Mid (base)
+// CHECK:  0 | void * p
+// CHECK:  0 |   struct E2 (base) (empty)
+// CHECK:| [sizeof=8, align=8,
+// CHECK:|  nvsize=8, nvalign=8]
+
+
+struct E1 {};
+struct E2 {};
+struct Mid {void *p; };
+struct __declspec(empty_bases) Combine : E1, Mid, E2 {};
+Combine g;
+
Index: clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/override-layout-ms.layout
@@ -0,0 +1,39 @@
+*** Dumping AST Record Layout
+Type: struct E1
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Mid
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: [0]>
+
+*** Dumping AST Record Layout
+Type: struct E2
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct Combine
+
+Layout: 
+  VBaseOffsets: []>
+  FieldOffsets: []>
Index: clang/lib/Frontend/LayoutOverrideSource.cpp
===
--- clang/lib/Frontend/LayoutOverrideSource.cpp
+++ clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Frontend/LayoutOverrideSource.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -26,6 +27,20 @@
   return S.substr(0, Offset).str();
 }
 
+/// Parse an unsigned integer and move S to the next non-digit character.
+static bool parseUnsigned(StringRef , unsigned long long ) {
+  if (S.empty() || !isDigit(S[0]))
+return false;
+  unsigned Idx = 1;
+  while (Idx < S.size() && isDigit(S[Idx]))
+++Idx;
+  unsigned long long Offset = 0;
+  (void)S.substr(0, Idx).getAsInteger(10, Offset);
+  S = S.substr(Idx);
+  ULL = Offset;
+  return true;
+}
+
 LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
   std::ifstream Input(Filename.str().c_str());
   if (!Input.is_open())
@@ -80,8 +95,8 @@
   LineStr = LineStr.substr(Pos + strlen(" Size:"));
 
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size;
   continue;
 }
 
@@ -92,12 +107,13 @@
   LineStr = LineStr.substr(Pos + strlen("Alignment:"));
 
   unsigned long long Alignment = 0;
-  (void)LineStr.getAsInteger(10, Alignment);
-  CurrentLayout.Align = Alignment;
+  if (parseUnsigned(LineStr, Alignment))
+CurrentLayout.Align = Alignment;
   continue;
 }
 
-// Check for the size/alignment of the type.
+// Check for the size/alignment of the type. The number follows "size=" or
+// "align=" indicates number of bytes.
 Pos = LineStr.find("sizeof=");
 if (Pos != StringRef::npos) {
   /* Skip past the sizeof= prefix. */
@@ -105,8 +121,8 @@
 
   // Parse size.
   unsigned long long Size = 0;
-  (void)LineStr.getAsInteger(10, Size);
-  CurrentLayout.Size = Size;
+  if (parseUnsigned(LineStr, Size))
+CurrentLayout.Size = Size * 8;
 
   Pos = LineStr.find("align=");
   if (Pos != StringRef::npos) {
@@ -115,8 

[PATCH] D152472: [Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.

2023-06-08 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added a reviewer: rnk.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This assertion triggered when we have two base classes sharing the same offset
and the first base is empty and the second class is non-empty.
Remove it for correctness.

I can't add a test case for this because -foverride-record-layout doesn't read
base class info at all. I can add that support later for testing if needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152472

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp


Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2926,8 +2926,7 @@
   bool FoundBase = false;
   if (UseExternalLayout) {
 FoundBase = External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
-if (FoundBase) {
-  assert(BaseOffset >= Size && "base offset already allocated");
+if (BaseOffset > Size) {
   Size = BaseOffset;
 }
   }


Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2926,8 +2926,7 @@
   bool FoundBase = false;
   if (UseExternalLayout) {
 FoundBase = External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
-if (FoundBase) {
-  assert(BaseOffset >= Size && "base offset already allocated");
+if (BaseOffset > Size) {
   Size = BaseOffset;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150817: Use windows baskslash on anonymous tag locations if using MSVCFormatting and it's not absolute path.

2023-05-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D150817#4356305 , @TWeaver wrote:

> Hello and good afternoon from the UK,
>
> I believe this patch has caused failures on the following buildbot:
>
> https://lab.llvm.org/buildbot/#/builders/216/builds/21493
>
> are you able to take a look?
>
> thanks,
> Tom W

Thanks for reporting. Hope this fix it: 
https://reviews.llvm.org/rGfe69bb64415ef6fe01ebbb1d1a801e85bd6bd879.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150817/new/

https://reviews.llvm.org/D150817

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


[PATCH] D150817: Use windows baskslash on anonymous tag locations if using MSVCFormatting and it's not absolute path.

2023-05-19 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75993812d5c1: Use windows baskslash on anonymous tag 
locations if using MSVCFormatting and… (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D150817?vs=523171=523742#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150817/new/

https://reviews.llvm.org/D150817

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CodeGen/Inputs/debug-info-slash.cpp
  clang/test/CodeGen/Inputs/debug-info-slash.h
  clang/test/CodeGen/debug-info-slash.test


Index: clang/test/CodeGen/debug-info-slash.test
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.test
@@ -0,0 +1,10 @@
+RUN: rm -rf %t-dir
+RUN: mkdir -p %t-dir/header/Inputs
+RUN: cp %S/Inputs/debug-info-slash.cpp %t-dir/
+RUN: cp %S/Inputs/debug-info-slash.h %t-dir/header/Inputs
+RUN: cd %t-dir
+RUN: %clang -target x86_64-pc-win32 -emit-llvm -S -g  
%t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=WIN %s
+RUN: %clang -target x86_64-linux-gnu -emit-llvm -S -g  
%t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=LINUX %s
+
+WIN:   lambda at header\\Inputs\\debug-info-slash.h
+LINUX: lambda at header/Inputs/debug-info-slash.h
Index: clang/test/CodeGen/Inputs/debug-info-slash.h
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.h
@@ -0,0 +1,6 @@
+template 
+void f1() {}
+void a() {
+  auto Lambda = [] {};
+  f1();
+}
Index: clang/test/CodeGen/Inputs/debug-info-slash.cpp
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.cpp
@@ -0,0 +1,2 @@
+#include "Inputs/debug-info-slash.h"
+int main() { a(); return 0; }
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1385,11 +1385,18 @@
   if (PLoc.isValid()) {
 OS << " at ";
 StringRef File = PLoc.getFilename();
+llvm::SmallString<1024> WrittenFile(File);
 if (auto *Callbacks = Policy.Callbacks)
-  OS << Callbacks->remapPath(File);
-else
-  OS << File;
-OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
+  WrittenFile = Callbacks->remapPath(File);
+// Fix inconsistent path separator created by
+// clang::DirectoryLookup::LookupFile when the file path is relative
+// path.
+llvm::sys::path::Style Style =
+!llvm::sys::path::is_absolute(WrittenFile) && Policy.MSVCFormatting
+? llvm::sys::path::Style::windows_backslash
+: llvm::sys::path::Style::native;
+llvm::sys::path::native(WrittenFile, Style);
+OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
   }
 }
 


Index: clang/test/CodeGen/debug-info-slash.test
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.test
@@ -0,0 +1,10 @@
+RUN: rm -rf %t-dir
+RUN: mkdir -p %t-dir/header/Inputs
+RUN: cp %S/Inputs/debug-info-slash.cpp %t-dir/
+RUN: cp %S/Inputs/debug-info-slash.h %t-dir/header/Inputs
+RUN: cd %t-dir
+RUN: %clang -target x86_64-pc-win32 -emit-llvm -S -g  %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=WIN %s
+RUN: %clang -target x86_64-linux-gnu -emit-llvm -S -g  %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=LINUX %s
+
+WIN:   lambda at header\\Inputs\\debug-info-slash.h
+LINUX: lambda at header/Inputs/debug-info-slash.h
Index: clang/test/CodeGen/Inputs/debug-info-slash.h
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.h
@@ -0,0 +1,6 @@
+template 
+void f1() {}
+void a() {
+  auto Lambda = [] {};
+  f1();
+}
Index: clang/test/CodeGen/Inputs/debug-info-slash.cpp
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.cpp
@@ -0,0 +1,2 @@
+#include "Inputs/debug-info-slash.h"
+int main() { a(); return 0; }
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1385,11 +1385,18 @@
   if (PLoc.isValid()) {
 OS << " at ";
 StringRef File = PLoc.getFilename();
+llvm::SmallString<1024> WrittenFile(File);
 if (auto *Callbacks = Policy.Callbacks)
-  OS << Callbacks->remapPath(File);
-else
-  OS << File;
-OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
+  WrittenFile = Callbacks->remapPath(File);
+// Fix 

[PATCH] D150817: Use windows baskslash on anonymous tag locations if using MSVCFormatting and it's not absolute path.

2023-05-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added a reviewer: hans.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes a nondeterminism on debug info when building on windows natively vs
cross building to windows.

[1] 
https://github.com/llvm/llvm-project/blob/llvmorg-17-init/clang/lib/Lex/HeaderSearch.cpp#L465


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150817

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CodeGen/Inputs/debug-info-slash.cpp
  clang/test/CodeGen/Inputs/debug-info-slash.h
  clang/test/CodeGen/debug-info-slash.test


Index: clang/test/CodeGen/debug-info-slash.test
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.test
@@ -0,0 +1,10 @@
+RUN: rm -rf %t-dir
+RUN: mkdir -p %t-dir/header/Inputs
+RUN: cp %S/Inputs/debug-info-slash.cpp %t-dir/
+RUN: cp %S/Inputs/debug-info-slash.h %t-dir/header/Inputs
+RUN: cd %t-dir
+RUN: %clang -target x86_64-pc-win32 -emit-llvm -S -g  
%t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=WIN %s
+RUN: %clang -target x86_64-linux-gnu -emit-llvm -S -g  
%t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=LINUX %s
+
+WIN:   lambda at header\\Inputs\\debug-info-slash.h
+LINUX: lambda at header/Inputs/debug-info-slash.h
Index: clang/test/CodeGen/Inputs/debug-info-slash.h
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.h
@@ -0,0 +1,6 @@
+template 
+void f1() {}
+void a() {
+  auto Lambda = [] {};
+  f1();
+}
Index: clang/test/CodeGen/Inputs/debug-info-slash.cpp
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.cpp
@@ -0,0 +1,2 @@
+#include "Inputs/debug-info-slash.h"
+int main() { a(); return 0; }
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1385,11 +1385,18 @@
   if (PLoc.isValid()) {
 OS << " at ";
 StringRef File = PLoc.getFilename();
+llvm::SmallString<1024> WrittenFile(File);
 if (auto *Callbacks = Policy.Callbacks)
-  OS << Callbacks->remapPath(File);
-else
-  OS << File;
-OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
+  WrittenFile = Callbacks->remapPath(File);
+// The following tries to fix inconsistent path separator created by
+// clang::DirectoryLookup::LookupFile when the file path is relative
+// path.
+llvm::sys::path::Style Style =
+!llvm::sys::path::is_absolute(WrittenFile) && Policy.MSVCFormatting
+? llvm::sys::path::Style::windows_backslash
+: llvm::sys::path::Style::native;
+llvm::sys::path::native(WrittenFile, Style);
+OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
   }
 }
 


Index: clang/test/CodeGen/debug-info-slash.test
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.test
@@ -0,0 +1,10 @@
+RUN: rm -rf %t-dir
+RUN: mkdir -p %t-dir/header/Inputs
+RUN: cp %S/Inputs/debug-info-slash.cpp %t-dir/
+RUN: cp %S/Inputs/debug-info-slash.h %t-dir/header/Inputs
+RUN: cd %t-dir
+RUN: %clang -target x86_64-pc-win32 -emit-llvm -S -g  %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=WIN %s
+RUN: %clang -target x86_64-linux-gnu -emit-llvm -S -g  %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=LINUX %s
+
+WIN:   lambda at header\\Inputs\\debug-info-slash.h
+LINUX: lambda at header/Inputs/debug-info-slash.h
Index: clang/test/CodeGen/Inputs/debug-info-slash.h
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.h
@@ -0,0 +1,6 @@
+template 
+void f1() {}
+void a() {
+  auto Lambda = [] {};
+  f1();
+}
Index: clang/test/CodeGen/Inputs/debug-info-slash.cpp
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/debug-info-slash.cpp
@@ -0,0 +1,2 @@
+#include "Inputs/debug-info-slash.h"
+int main() { a(); return 0; }
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1385,11 +1385,18 @@
   if (PLoc.isValid()) {
 OS << " at ";
 StringRef File = PLoc.getFilename();
+llvm::SmallString<1024> WrittenFile(File);
 if (auto *Callbacks = Policy.Callbacks)
-  OS << Callbacks->remapPath(File);
-else
-  OS << File;
-OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
+  WrittenFile = Callbacks->remapPath(File);

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-17 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab8f622c79b2: [DebugInfo] Fix file path separator when 
targeting windows. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/Driver/cl-outputs.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,6 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
 PathRef = PathStore;
   }
 
Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -294,3 +294,12 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
+
+// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=ABSOLUTE_OBJPATH %s
+// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
+// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
+// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -563,6 +563,16 @@
 // Make the path absolute in the debug infos like MSVC does.
 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
   }
+  // If the object file name is a relative path, then always use Windows
+  // backslash style as -object-file-name is used for embedding object file path
+  // in codeview and it can only be generated when targeting on Windows.
+  // Otherwise, just use native absolute path.
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native
+  : llvm::sys::path::Style::windows_backslash;
+  llvm::sys::path::remove_dots(ObjFileNameForDebug, /*remove_dot_dot=*/true,
+   Style);
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-object-file-name=") + ObjFileNameForDebug));
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the 

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:583
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native

hans wrote:
> zequanwu wrote:
> > hans wrote:
> > > zequanwu wrote:
> > > > hans wrote:
> > > > > Won't the code above (line 580) make many filenames absolute and 
> > > > > cause us to use native slashes even when we want backslashes?
> > > > > 
> > > > > This would also need a test.
> > > > > Won't the code above (line 580) make many filenames absolute and 
> > > > > cause us to use native slashes even when we want backslashes?
> > > > Yes, I don't think we should change anything if it's converted to an 
> > > > absolute path.
> > > > 
> > > > Only if the `-fdebug-compilation-dir` is not given or is an absolute 
> > > > path, the path in `/Fo` will be converted to absolute path. Users can 
> > > > avoid the path being converted to absolute path by passing a relative 
> > > > path to `-fdebug-compilation-dir`, just like what we do in chrome build 
> > > > (`-fdebug-compilation-dir=.`).
> > > > 
> > > > Added a test.
> > > Apologies for all the questions, but I find the logic a bit complex 
> > > still. The test cases are helpful though.
> > > 
> > > Could we simplify by just always using Windows slashes here, regardless 
> > > of `-fdebug-compilation-dir` etc.?
> > The object file path will be converted to absolute path depending on 
> > whether `-fdebug-compilation-dir` is given or whether it's absolute path. I 
> > don't think we want to change a native absolute path of object file to use 
> > Windows slashes. Or this could happen on linux: `/usr/local/src/a.obj` -> 
> > `\usr\local\src\a.obj`. So, we only use windows slashes when it's not an 
> > absolute path here.
> Thanks, that makes sense. Can you add a comment with that explanation?
Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 514287.
zequanwu marked an inline comment as done.
zequanwu added a comment.

Add comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/Driver/cl-outputs.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,6 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
 PathRef = PathStore;
   }
 
Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -294,3 +294,12 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
+
+// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=ABSOLUTE_OBJPATH %s
+// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
+// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
+// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,6 +579,16 @@
 // Make the path absolute in the debug infos like MSVC does.
 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
   }
+  // If the object file name is a relative path, then always use Windows
+  // backslash style as -object-file-name is used for embedding object file path
+  // in codeview and it can only be generated when targeting on Windows.
+  // Otherwise, just use native absolute path.
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native
+  : llvm::sys::path::Style::windows_backslash;
+  llvm::sys::path::remove_dots(ObjFileNameForDebug, /*remove_dot_dot=*/true,
+   Style);
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-object-file-name=") + ObjFileNameForDebug));
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions  = 

[PATCH] D148529: [clang] Replace find_executable with shutil.which in creduce script

2023-04-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu accepted this revision.
zequanwu added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148529/new/

https://reviews.llvm.org/D148529

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:583
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native

hans wrote:
> zequanwu wrote:
> > hans wrote:
> > > Won't the code above (line 580) make many filenames absolute and cause us 
> > > to use native slashes even when we want backslashes?
> > > 
> > > This would also need a test.
> > > Won't the code above (line 580) make many filenames absolute and cause us 
> > > to use native slashes even when we want backslashes?
> > Yes, I don't think we should change anything if it's converted to an 
> > absolute path.
> > 
> > Only if the `-fdebug-compilation-dir` is not given or is an absolute path, 
> > the path in `/Fo` will be converted to absolute path. Users can avoid the 
> > path being converted to absolute path by passing a relative path to 
> > `-fdebug-compilation-dir`, just like what we do in chrome build 
> > (`-fdebug-compilation-dir=.`).
> > 
> > Added a test.
> Apologies for all the questions, but I find the logic a bit complex still. 
> The test cases are helpful though.
> 
> Could we simplify by just always using Windows slashes here, regardless of 
> `-fdebug-compilation-dir` etc.?
The object file path will be converted to absolute path depending on whether 
`-fdebug-compilation-dir` is given or whether it's absolute path. I don't think 
we want to change a native absolute path of object file to use Windows slashes. 
Or this could happen on linux: `/usr/local/src/a.obj` -> 
`\usr\local\src\a.obj`. So, we only use windows slashes when it's not an 
absolute path here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:583
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native

hans wrote:
> Won't the code above (line 580) make many filenames absolute and cause us to 
> use native slashes even when we want backslashes?
> 
> This would also need a test.
> Won't the code above (line 580) make many filenames absolute and cause us to 
> use native slashes even when we want backslashes?
Yes, I don't think we should change anything if it's converted to an absolute 
path.

Only if the `-fdebug-compilation-dir` is not given or is an absolute path, the 
path in `/Fo` will be converted to absolute path. Users can avoid the path 
being converted to absolute path by passing a relative path to 
`-fdebug-compilation-dir`, just like what we do in chrome build 
(`-fdebug-compilation-dir=.`).

Added a test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 513611.
zequanwu added a comment.

Added clang-cl option test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/Driver/cl-outputs.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,6 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
 PathRef = PathStore;
   }
 
Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -294,3 +294,12 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
+
+// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=ABSOLUTE_OBJPATH %s
+// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
+// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
+// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,6 +579,12 @@
 // Make the path absolute in the debug infos like MSVC does.
 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
   }
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native
+  : llvm::sys::path::Style::windows_backslash;
+  llvm::sys::path::remove_dots(ObjFileNameForDebug, /*remove_dot_dot=*/true,
+   Style);
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-object-file-name=") + ObjFileNameForDebug));
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions  = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-13 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 513252.
zequanwu added a comment.
Herald added a subscriber: MaskRay.

- Move remove_dots to clang driver.
- Revert changes to llc.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-slash.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,6 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
 PathRef = PathStore;
   }
 
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g 
%s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g 
%s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,6 +579,12 @@
 // Make the path absolute in the debug infos like MSVC does.
 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
   }
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native
+  : llvm::sys::path::Style::windows_backslash;
+  llvm::sys::path::remove_dots(ObjFileNameForDebug, /*remove_dot_dot=*/true,
+   Style);
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-object-file-name=") + ObjFileNameForDebug));
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions  = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -479,9 +479,9 @@
   /// The seed used by the randomize structure layout feature.
   std::string RandstructSeed;
 
-  /// Indicates whether the __FILE__ macro should use the target's
-  /// platform-specific file separator or whether it should use the build
-  /// environment's platform-specific file separator.
+  /// Indicates whether to use target's platform-specific file separator when
+  /// __FILE__ macro is used and when concatenating filename with directory or
+  /// to use build environment environment's platform-specific file separator.
   ///
   /// The plaform-specific path separator is the backslash(\) for Windows and
   /// forward slash (/) elsewhere.


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-13 Thread Zequan Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0529da5b948c: [Coverage] Handle invalid end location of an 
expression/statement. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D147073?vs=512971=513236#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CoverageMappingGen.cpp


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not 
valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@
   not a type concept.
 - Fix crash when a doc comment contains a line splicing.
   (`#62054 `_)
+- Work around with a clang coverage crash which happens when visiting 
+  expressions/statements with invalid source locations in non-assert builds. 
+  Assert builds may still see assertions triggered from this.
+  (`#62105 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@
   not a type concept.
 - Fix crash when a doc comment contains a 

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 512971.
zequanwu edited the summary of this revision.
zequanwu added a comment.

- Filed an github issue:
- Added release note.
- Updated commit message and summary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CoverageMappingGen.cpp


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not 
valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
 - Fix false-positive diagnostic issued for consteval initializers of temporary
   objects.
   (`#60286 `_)
+- Work around with a clang coverage crash which happens when visiting 
+  expressions/statements with invalid source locations in non-assert builds. 
+  Assert builds may still see assertions triggered from this.
+  (`#62105 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
 - Fix false-positive diagnostic issued for consteval initializers of temporary
   objects.
   (`#60286 

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4261949 , @hans wrote:

>> Well, MSVC cl removes redundant dots so we shouldn't remove 
>> llvm::sys::path::remove_dots.
>
> Could we do the `remove_dots` on the Clang side, where we can decide based on 
> the LangOpts?

Yes, we can do that. Is there a reason to favor there over here? At here, the 
object path in llc output can also benefits from `remove_dots`, not just clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 512868.
zequanwu added a comment.

Add assertion on source locations in `pushRegion`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not 
valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147073#4258981 , @aaron.ballman 
wrote:

> In D147073#4258664 , @zequanwu 
> wrote:
>
>> In D147073#4258529 , 
>> @aaron.ballman wrote:
>>
>>> In D147073#4258426 , @zequanwu 
>>> wrote:
>>>
 In D147073#4258396 , 
 @aaron.ballman wrote:

> In D147073#4258384 , @hans 
> wrote:
>
>> Again not an expert here, but lgtm.
>>
>> (Nit: the 
>> https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExprCXX.cpp#L1528-L1530
>>  link in the description seems to point to the wrong code now, since 
>> main changed. Here is a link for 16.0.1: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536)
>
> I'm confused -- I thought D147569  
> resolved the issue and so this patch is no longer needed?

 D147569  fixes 
 https://github.com/llvm/llvm-project/issues/45481. This one fixes another 
 issue crbug.com/1427933. Their stack trace look similar but not caused by 
 the same issue.

 Updated the link in summary to: 
 https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536
>>>
>>> Thank you for clarifying, I was confused. :-)
>>>
>>> I don't think the changes here are correct either -- it's glossing over an 
>>> issue that we're not properly tracking the source location in the AST. 
>>> Playing around with the reduced example is interesting though. If you 
>>> remove the default argument in the `T` constructor, the issue goes away. If 
>>> you stop using a forward declaration in the instantiation of `T`, the issue 
>>> goes away. If `S1` isn't a template, the issue goes away (but the issue 
>>> will come back if you then make `foo()` a template instead of `S1`). So it 
>>> seems that something about template instantiation is dropping the source 
>>> location information (perhaps) and we should be trying to track down where 
>>> that is to fix the root cause rather than work around it here for coverage 
>>> mapping alone. (The end location being incorrect can impact other things 
>>> that are harder to test because it'll be for things like fix-its that don't 
>>> work properly, which are easy to miss.)
>>
>> I agree that the real fix is to fix the source location information. If I 
>> just change [1] to `SourceRange Locs = SourceRange(LParenOrBraceLoc, 
>> RParenOrBraceLoc);`, the crash is gone. However, as the "FIXME" comment in 
>> [1] says, it's an intended work-around to drop source locations here. So, 
>> I'm assuming this kind of source location work-around could happen in 
>> multiple places in clang, and could happen in the future as a temporary 
>> work-around. Instead of crashing clang coverage for those work-around, we 
>> can at least skip coverage info for those expressions/statements.
>>
>> [1]: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1538
>
> Ugh, that workaround is unfortunate.
>
> You are correct that this same situation may come up in the future, but each 
> time it happens, I think it's a bug in the FE that needs to be addressed. I 
> worry that silencing the issues here will 1) lead to the actual bug staying 
> in the code base forever, and 2) be used as justification for making the same 
> workaround elsewhere in the code base, perhaps so often that it becomes "the 
> way things are supposed to work".
>
> Perhaps a way to split the middle would be to assert that the source 
> locations are valid in coverage mapping, but then do the right thing in 
> non-asserts builds instead of crashing. This way, we don't lose the benefit 
> of knowing the issues happen in development builds, but we don't punish users 
> of coverage mapping with the released product. WDYT?

Won't this still cause assertion failure on assert builds? I don't quite 
understand "do the right thing in non-asserts builds instead of crashing".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4258419 , @zequanwu wrote:

> In D147256#4257797 , @hans wrote:
>
>> In D147256#4249527 , @zequanwu 
>> wrote:
>>
>>> - Add a `-use-target-path-separator` flag for llc.
>>> - Add test for llc with that flag.
>>
>> But where does `TM.Options.ObjectFilenameForDebug` come from? Presumably it 
>> comes from Clang at some point, so is there any chance we can fix it "at the 
>> source" instead?
>
> `TM.Options.ObjectFilenameForDebug` either comes from llc's `-o` or 
> clang-cl's `object-file-name=` which is translated from `/Fo[ObjectFileName]`.
>
> For Chromium, the `/Fo[ObjectFileName]` we pass to clang-cl is the same when 
> building on Windows and targeting Windows from Linux. The problem comes 
> `llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);` in 
> `CodeViewDebug.cpp`. That function always convert the path to use host's path 
> separator. And I don't think we can write a `remove_dots` function that 
> doesn't change path separator, because `\` can only be used as path separator 
> on Windows but is a valid path character on Linux.
>
> Or we could just not use `llvm::sys::path::remove_dots`, use the user's input 
> as it is for object file path.

Well, MSVC cl removes redundant dots so we shouldn't remove 
`llvm::sys::path::remove_dots`. 
Generally, I think it's okay to use target path separator for object file path 
in codeview when user input is not an absolute path, because we can only 
generate codeview when targeting on windows.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147073#4258529 , @aaron.ballman 
wrote:

> In D147073#4258426 , @zequanwu 
> wrote:
>
>> In D147073#4258396 , 
>> @aaron.ballman wrote:
>>
>>> In D147073#4258384 , @hans wrote:
>>>
 Again not an expert here, but lgtm.

 (Nit: the 
 https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExprCXX.cpp#L1528-L1530
  link in the description seems to point to the wrong code now, since main 
 changed. Here is a link for 16.0.1: 
 https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536)
>>>
>>> I'm confused -- I thought D147569  
>>> resolved the issue and so this patch is no longer needed?
>>
>> D147569  fixes 
>> https://github.com/llvm/llvm-project/issues/45481. This one fixes another 
>> issue crbug.com/1427933. Their stack trace look similar but not caused by 
>> the same issue.
>>
>> Updated the link in summary to: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536
>
> Thank you for clarifying, I was confused. :-)
>
> I don't think the changes here are correct either -- it's glossing over an 
> issue that we're not properly tracking the source location in the AST. 
> Playing around with the reduced example is interesting though. If you remove 
> the default argument in the `T` constructor, the issue goes away. If you stop 
> using a forward declaration in the instantiation of `T`, the issue goes away. 
> If `S1` isn't a template, the issue goes away (but the issue will come back 
> if you then make `foo()` a template instead of `S1`). So it seems that 
> something about template instantiation is dropping the source location 
> information (perhaps) and we should be trying to track down where that is to 
> fix the root cause rather than work around it here for coverage mapping 
> alone. (The end location being incorrect can impact other things that are 
> harder to test because it'll be for things like fix-its that don't work 
> properly, which are easy to miss.)

I agree that the real fix is to fix the source location information. If I just 
change [1] to `SourceRange Locs = SourceRange(LParenOrBraceLoc, 
RParenOrBraceLoc);`, the crash is gone. However, as the "FIXME" comment in [1] 
says, it's an intended work-around to drop source locations here. So, I'm 
assuming this kind of source location work-around could happen in multiple 
places in clang, and could happen in the future as a temporary work-around. 
Instead of crashing clang coverage for those work-around, we can at least skip 
coverage info for those expressions/statements.

[1]: 
https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1538


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147073#4258396 , @aaron.ballman 
wrote:

> In D147073#4258384 , @hans wrote:
>
>> Again not an expert here, but lgtm.
>>
>> (Nit: the 
>> https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExprCXX.cpp#L1528-L1530
>>  link in the description seems to point to the wrong code now, since main 
>> changed. Here is a link for 16.0.1: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536)
>
> I'm confused -- I thought D147569  resolved 
> the issue and so this patch is no longer needed?

D147569  fixes 
https://github.com/llvm/llvm-project/issues/45481. This one fixes another issue 
crbug.com/1427933. Their stack trace look similar but not caused by the same 
issue.

Updated the link in summary to: 
https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-11 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4257797 , @hans wrote:

> In D147256#4249527 , @zequanwu 
> wrote:
>
>> - Add a `-use-target-path-separator` flag for llc.
>> - Add test for llc with that flag.
>
> But where does `TM.Options.ObjectFilenameForDebug` come from? Presumably it 
> comes from Clang at some point, so is there any chance we can fix it "at the 
> source" instead?

`TM.Options.ObjectFilenameForDebug` either comes from llc's `-o` or clang-cl's 
`object-file-name=` which is translated from `/Fo[ObjectFileName]`.

For Chromium, the `/Fo[ObjectFileName]` we pass to clang-cl is the same when 
building on Windows and targeting Windows from Linux. The problem comes 
`llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);` in 
`CodeViewDebug.cpp`. That function always convert the path to use host's path 
separator. And I don't think we can write a `remove_dots` function that doesn't 
change path separator, because `\` can only be used as path separator on 
Windows but is a valid path character on Linux.

Or we could just not use `llvm::sys::path::remove_dots`, use the user's input 
as it is for object file path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-06 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 511496.
zequanwu added a comment.

- Add a `-use-target-path-separator` flag for llc.
- Add test for llc with that flag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/test/DebugInfo/COFF/use-target-path-separator.ll

Index: llvm/test/DebugInfo/COFF/use-target-path-separator.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/use-target-path-separator.ll
@@ -0,0 +1,35 @@
+; RUN: rm -rf %t-dir
+; RUN: mkdir -p %t-dir/subdir
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc -use-target-path-separator %s -o subdir/win.obj
+; RUN: llvm-readobj --codeview subdir/win.obj | FileCheck --check-prefix=WIN %s
+
+; WIN: ObjectName: subdir\win.obj
+
+; ModuleID = 'D:\src\scopes\foo.cpp'
+source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp"
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-pc-windows-msvc19.0.23918"
+
+define i32 @"?foo@@YAHXZ"() !dbg !10 {
+entry:
+  ret i32 42, !dbg !14
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!7, !8}
+!llvm.ident = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+; One .debug$S section should contain an S_COMPILE3 record that identifies the
+; source language and the version of the compiler based on the DICompileUnit.
+!1 = !DIFile(filename: "D:\5Csrc\5Cscopes\5Cfoo.cpp", directory: "D:\5Csrc\5Cscopes\5Cclang")
+!2 = !{}
+!7 = !{i32 2, !"CodeView", i32 1}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{!"clang version 4.0.0 "}
+!10 = distinct !DISubprogram(name: "foo", linkageName: "\01?foo@@YAHXZ", scope: !1, file: !1, line: 1, type: !11, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13}
+!13 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!14 = !DILocation(line: 2, scope: !10)
Index: llvm/lib/CodeGen/CommandFlags.cpp
===
--- llvm/lib/CodeGen/CommandFlags.cpp
+++ llvm/lib/CodeGen/CommandFlags.cpp
@@ -104,6 +104,7 @@
 CGOPT(unsigned, AlignLoops)
 CGOPT(bool, JMCInstrument)
 CGOPT(bool, XCOFFReadOnlyPointers)
+CGOPT(bool, UseTargetPathSeparator)
 
 codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
 #define CGBINDOPT(NAME)\
@@ -486,6 +487,14 @@
   cl::init(false));
   CGBINDOPT(XCOFFReadOnlyPointers);
 
+  static cl::opt UseTargetPathSeparator(
+  "use-target-path-separator",
+  cl::desc(
+  "Use target's platform-specific file separator when concatenating "
+  "filename with directory."),
+  cl::init(false));
+  CGBINDOPT(UseTargetPathSeparator);
+
 #undef CGBINDOPT
 
   mc::RegisterMCTargetOptionsFlags();
@@ -563,6 +572,7 @@
   Options.LoopAlignment = getAlignLoops();
   Options.JMCInstrument = getJMCInstrument();
   Options.XCOFFReadOnlyPointers = getXCOFFReadOnlyPointers();
+  Options.UseTargetPathSeparator = getUseTargetPathSeparator();
 
   Options.MCOptions = mc::InitMCTargetOptionsFromFlags();
 
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,15 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+(!llvm::sys::path::is_absolute(PathRef,
+   llvm::sys::path::Style::posix) &&
+ Asm->TM.Options.UseTargetPathSeparator)
+? (Asm->TM.getTargetTriple().isOSWindows()
+   ? llvm::sys::path::Style::windows_backslash
+   : llvm::sys::path::Style::posix)
+: llvm::sys::path::Style::native;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -127,7 +127,8 @@
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
 

[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Added the missing release note at rG5bab9097ce5b093289e8d40809d02f002febe910 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147569/new/

https://reviews.llvm.org/D147569

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


[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e93bd417445: [Coverage] Fix crash when visiting 
PseudoObjectExpr. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147569/new/

https://reviews.llvm.org/D147569

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/if.cpp
  clang/test/CoverageMapping/strong_order.cpp

Index: clang/test/CoverageMapping/strong_order.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/strong_order.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 = #0
@@ -70,7 +78,17 @@
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 -> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> [[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> [[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> [[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> [[@LINE-2]]:23 = #8
+// CHECK-NEXT: File 0, [[@LINE-3]]:23 -> [[@LINE-1]]:4 = #8
 }
 
 #define FOO true
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1566,6 +1566,15 @@
 // Lambdas are treated as their own functions for now, so we shouldn't
 // propagate counts into them.
   }
+
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+// Just visit syntatic expression 

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 58.
zequanwu added a comment.
Herald added a subscriber: ormris.

- Pass `LangOptions.UseTargetPathSeparator` down to TargetOptions to use host

path separator when it's set.

- Add a test case. The problem is when if we are targeting to linux, clang

won't generate codeview debuginfo with `-gcodeview`. So, I only add the test to
target on windows.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/CodeGen/use-target-path-separator.c
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,15 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+(!llvm::sys::path::is_absolute(PathRef,
+   llvm::sys::path::Style::posix) &&
+ Asm->TM.Options.UseTargetPathSeparator)
+? (Asm->TM.getTargetTriple().isOSWindows()
+   ? llvm::sys::path::Style::windows_backslash
+   : llvm::sys::path::Style::posix)
+: llvm::sys::path::Style::native;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -127,7 +127,8 @@
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
   ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
-  HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
+  HonorSignDependentRoundingFPMathOption(false),
+  UseTargetPathSeparator(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
   DisableIntegratedAS(false), RelaxELFRelocations(true),
@@ -206,6 +207,11 @@
 unsigned HonorSignDependentRoundingFPMathOption : 1;
 bool HonorSignDependentRoundingFPMath() const;
 
+/// UseTargetPathSeparator - This Indicates whether to use target's
+/// platform-specific file separator when concatenating filename with
+/// directory.
+unsigned UseTargetPathSeparator : 1;
+
 /// NoZerosInBSS - By default some codegens place zero-initialized data to
 /// .bss section. This flag disables such behaviour (necessary, e.g. for
 /// crt*.o compiling).
Index: clang/test/CodeGen/use-target-path-separator.c
===
--- /dev/null
+++ clang/test/CodeGen/use-target-path-separator.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t-dir
+// RUN: mkdir -p %t-dir/subdir
+// RUN: cd %t-dir
+// RUN: %clang_cl --target=x86_64-windows-msvc -ffile-reproducible /c /Z7 -fdebug-compilation-dir=. /Fosubdir/win.obj -- %s
+// RUN: llvm-readobj --codeview subdir/win.obj | FileCheck --check-prefix=WIN %s
+
+int main (void) {
+  return 0;
+}
+
+// WIN: ObjectName: subdir\win.obj
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-04 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510938.
zequanwu added a comment.

Split to another patch: D147569 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/invalid_location.cpp


Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++20 -stdlib=libc++ -triple %itanium_abi_triple %s | 
FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//now because 'T{}' doesn't have a valid end location for now.
+//Once it's fixed, correct the following two "CHECK-NETX" and #3 and #2
+//may need to swap positions.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)
+
+// CHECK-NEXT:   File 0, 14:5 -> 14:6 = #0
+// CHECK-NEXT:   Branch,File 0, 14:5 -> 14:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 14:8 -> 14:9 = #2
+// CHECK-NEXT:   File 0, 14:9 -> 14:10 = #2
+// CHECK-NEXT:   File 0, 14:13 -> 14:14 = (#0 - #2)
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
@@ -891,6 +899,8 @@
   /// Find a valid gap range between \p AfterLoc and \p BeforeLoc.
   std::optional findGapAreaBetween(SourceLocation AfterLoc,
 SourceLocation BeforeLoc) {
+if (AfterLoc.isInvalid() || BeforeLoc.isInvalid())
+  return std::nullopt;
 // If AfterLoc is in function-like macro, use the right parenthesis
 // location.
 if (AfterLoc.isMacroID()) {


Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -stdlib=libc++ -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//

[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-04 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510918.
zequanwu added a comment.

Add the crash repro as test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147569/new/

https://reviews.llvm.org/D147569

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/if.cpp
  clang/test/CoverageMapping/strong_order.cpp

Index: clang/test/CoverageMapping/strong_order.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/strong_order.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 = #0
@@ -70,7 +78,17 @@
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 -> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> [[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> [[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> [[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> [[@LINE-2]]:23 = #8
+// CHECK-NEXT: File 0, [[@LINE-3]]:23 -> [[@LINE-1]]:4 = #8
 }
 
 #define FOO true
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1566,6 +1566,15 @@
 // Lambdas are treated as their own functions for now, so we shouldn't
 // propagate counts into them.
   }
+
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+// Just visit syntatic expression as this is what users actually write.
+VisitStmt(POE->getSyntacticForm());
+  }
+
+  void VisitOpaqueValueExpr(const 

[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-04 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: aaron.ballman, gulfem, hans.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a split of D147073 .

Fixes #45481


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147569

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/if.cpp


Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp 
%s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp 
%s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 
= #0
@@ -70,7 +78,17 @@
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> 
[[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 
-> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> 
[[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> 
[[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> 
[[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> 
[[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> 
[[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> 
[[@LINE-2]]:23 = #8
+// CHECK-NEXT: File 0, [[@LINE-3]]:23 -> 
[[@LINE-1]]:4 = #8
 }
 
 #define FOO true
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1566,6 +1566,15 @@
 // Lambdas are treated as their own functions for now, so we shouldn't
 // propagate counts into them.
   }
+
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+// Just visit syntatic expression as this is what users actually write.
+VisitStmt(POE->getSyntacticForm());
+  }
+
+  void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
+Visit(OVE->getSourceExpr());
+  }
 };
 
 } // end anonymous namespace


Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 = #0
@@ -70,7 +78,17 @@
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 -> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> [[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> [[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> [[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, 

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510514.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/invalid_location.cpp

Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -stdlib=libc++ -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//now because 'T{}' doesn't have a valid end location for now.
+//Once it's fixed, correct the following two "CHECK-NETX" and #3 and #2
+//may need to swap positions.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)
+
+// CHECK-NEXT:   File 0, 14:5 -> 14:6 = #0
+// CHECK-NEXT:   Branch,File 0, 14:5 -> 14:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 14:8 -> 14:9 = #2
+// CHECK-NEXT:   File 0, 14:9 -> 14:10 = #2
+// CHECK-NEXT:   File 0, 14:13 -> 14:14 = (#0 - #2)
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
  

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu marked an inline comment as done.
zequanwu added a comment.

In D147073#4240017 , @hans wrote:

> I'm not familiar with this code. I suppose the question is whether it's 
> reasonable for this code to expect that the source locations are always valid 
> or not?

Yes.

For `0 ? T{} : T{};`, the both branches have valid start location but 
invalid end location. See comments at 
https://github.com/llvm/llvm-project/issues/45481#issuecomment-1487267814.

For the `std::strong_ordering`, I found that `DeclRefExpr` in the 
ConditionalOperator's true branch has invalid start and end locations. It might 
because it's inside a `PseudoObjectExpr`. Maybe we should simply just skip 
visiting `PseudoObjectExpr`, I see that its begin and end location are the 
same. I'm not familiar with that expression, so, I just handled it by adding 
checks for validating begin and end locations.

  PseudoObjectExpr 0x629f3bf0 'const strong_ordering':'const class 
std::strong_ordering' lvalue
  |-BinaryOperator 0x629f3bd0 'const strong_ordering':'const class 
std::strong_ordering' lvalue '<=>'
  | |-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  | | `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  | `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
  | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  |-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
  | `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  `-ConditionalOperator 0x629f3ba0 'const strong_ordering':'const class 
std::strong_ordering' lvalue
|-CXXOperatorCallExpr 0x629f3970 '_Bool' '==' adl
| |-ImplicitCastExpr 0x629f3958 '_Bool (*)(const S &, const S &)' 

| | `-DeclRefExpr 0x629f38d8 '_Bool (const S &, const S &)' lvalue 
Function 0x629f2a40 'operator==' '_Bool (const S &, const S &)'
| |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
| | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
| |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
| `-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
|   `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
| `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
|-DeclRefExpr 0x629f3b80 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a4ed8 'equal' 'const 
strong_ordering':'const class std::strong_ordering'
`-ConditionalOperator 0x629f3b50 'const strong_ordering':'const class 
std::strong_ordering' lvalue
  |-CXXOperatorCallExpr 0x629f3ab0 '_Bool' '<' adl
  | |-ImplicitCastExpr 0x629f3a98 '_Bool (*)(const S &, const S &)' 

  | | `-DeclRefExpr 0x629f3a78 '_Bool (const S &, const S &)' lvalue 
Function 0x629f27a0 'operator<' '_Bool (const S &, const S &)'
  | |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
  | | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  | |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct 
MyStruct' lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  | `-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
  |   `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  | `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct 
MyStruct' lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  |-DeclRefExpr 0x629f3b30 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a4c50 'less' 'const 
strong_ordering':'const class std::strong_ordering'
  `-DeclRefExpr 0x629f3ae8 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a5388 'greater' 'const 
strong_ordering':'const class std::strong_ordering'




Comment at: clang/test/CoverageMapping/invalid_location.cpp:31
+//now because 'T{}' doesn't have a valid end location for now.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)

hans 

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4236522 , @hans wrote:

> Thanks for working on this!
>
> The `-ffile-reproducible` flag name refers to making `#file` directives 
> reproducible, but `LangOptions.UseTargetPathSeparator` sounds a lot broader 
> :) I don't know what others think, but it would be nice to not have to 
> introduce any more flags at least.

Oh, I was already using `LangOptions.UseTargetPathSeparator`. Updated the 
comment on UseTargetPathSeparator.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:544
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);

hans wrote:
> Do we want to fix absolute filenames too?
> I can see arguments for and against:
> - Using what the user provided makes sense
> - Some build systems might use absolute paths for everything. But on the 
> other hand such builds have larger determinism problems (including the full 
> paths).
> So the current decision probably makes sense.
Yeah. If it's already absolute filename, it will just use that one user 
provided. 



Comment at: clang/test/CodeGen/debug-info-slash.c:5
+
+// WIN:   !DIFile(filename: "{{.*}}clang/test/CodeGen\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}clang/test/CodeGen/debug-info-slash.c"

hans wrote:
> Does the test runner write the 'clang/test/CodeGen' path with forward slashes 
> also on Windows?
No, it uses `clang\\test\\CodeGen`. Removed this part.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:787
 
   StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug);
   llvm::SmallString<256> PathStore(PathRef);

hans wrote:
> This handles codeview. Does anything need to be done for dwarf on windows? 
> mstorsjo might have input on that.
It looks like `TM.Options.ObjectFilenameForDebug` is only used for codeview. I 
guess dwarf doesn't store the object file path.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:18
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s 
--check-prefix=OBJ

hans wrote:
> Does this write the .o file into the test directory? I don't think that's 
> allowed (it may be read-only). But the test could create another subdirectory 
> under `%t-dir`.
It writes the .o file into the parent directory of the temporary dir %t-dir. It 
will just be the directory path of a normal `%t`, not the source test 
directory. The reason I'm not using `%t-dir/build-info.o` in the parent dir is 
because it will be translated into an absolute address. That will remain 
unchanged in ObjectName.



Comment at: llvm/test/DebugInfo/COFF/build-info.ll:21
+
+; OBJ: ObjectName: ..\build-info.o
+

hans wrote:
> But in the `llc` invocation, the user wrote a relative path with a forward 
> slash. What behavior do we want? What should happen if there are more then 
> one slash - I think remove_dots just works on the first one?
Yeah, the input uses forward slash but we convert it into backslash. When there 
are multiple slashs, they will all be converted into backslashs, which is done 
by `llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, 
llvm::sys::path::Style::windows_backslash);`. `remove_dots` not only remove 
redundant dots but also canonicalize path separator based on the style.

I think ideally we want just take what user provided as the ObjectName with the 
redundant dots removed. But `remove_dots` always canonicalizes the path 
separator based on the style. I don't find any function that doesn't 
canonicalize the path. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-31 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510057.
zequanwu marked 2 inline comments as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147256/new/

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/build-info.ll

Index: llvm/test/DebugInfo/COFF/build-info.ll
===
--- llvm/test/DebugInfo/COFF/build-info.ll
+++ llvm/test/DebugInfo/COFF/build-info.ll
@@ -10,6 +10,16 @@
 
 ; CHECK: {{.*}} | S_BUILDINFO [size = 8] BuildId = `[[INFO_IDX]]`
 
+; Test path is canonicalized to windows backslash style when output object file
+; name is not starting with '/'.
+; RUN: rm -rf %t-dir
+; RUN: mkdir %t-dir
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s --check-prefix=OBJ
+
+; OBJ: ObjectName: ..\build-info.o
+
 ; ModuleID = 'D:\src\scopes\foo.cpp'
 source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,11 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+llvm::sys::path::is_absolute(PathRef, llvm::sys::path::Style::posix)
+? llvm::sys::path::Style::posix
+: llvm::sys::path::Style::windows_backslash;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions  = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -479,9 +479,9 @@
   /// The seed used by the randomize structure layout feature.
   std::string RandstructSeed;
 
-  /// Indicates whether the __FILE__ macro should use the target's
-  /// platform-specific file separator or whether it should use the build
-  /// environment's platform-specific file separator.
+  /// Indicates whether to use target's platform-specific file separator when
+  /// __FILE__ macro is used and when concatenating filename with directory or
+  

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-03-30 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 509802.
zequanwu added a comment.

Add test case from 
https://github.com/llvm/llvm-project/issues/45481#issuecomment-981028897.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/invalid_location.cpp

Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -stdlib=libc++ -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//now because 'T{}' doesn't have a valid end location for now.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)
+
+// CHECK-NEXT:   File 0, 14:5 -> 14:6 = #0
+// CHECK-NEXT:   Branch,File 0, 14:5 -> 14:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 14:8 -> 14:9 = #2
+// CHECK-NEXT:   File 0, 14:9 -> 14:10 = #2
+// CHECK-NEXT:   File 0, 14:13 -> 14:14 = (#0 - #2)
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If the either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   

[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2023-03-30 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: lld/COFF/LTO.cpp:183
+  [&](size_t task, const Twine ) {
+buf[task].first = moduleName.str();
 return std::make_unique(

int3 wrote:
> Any reason why this doesn't instead store the module name in the 
> `file_names[task]` vector that the cache callback uses? Are the task IDs not 
> unique across each run of `ltoObj`, regardless of whether we end up using the 
> cache or not?
Users have to explicitly uses the flag `/opt:lldltocache=path` to let lld to 
search for cache files at the given folder. If it's not given, the callback of 
localCache won't be invoked. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-03-30 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: hans, aaron.ballman, ayzhao, aganea.
Herald added a subscriber: hiraditya.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This fixes two problems:

1. When crossing compiling for windows on linux, source file path in debug info

is concatenated with directory by host native separator ('/'). For windows
local build, they are concatenated by '\'. This causes non-determinism bug.

The solution here is to let `-ffile-reproducible` to control if we should use
host native separator or not.

2. Objectfile path in CodeView also uses host native separator when generated.

Make it always to use `\` unless the it's absolute path in posix style.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147256

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/build-info.ll


Index: llvm/test/DebugInfo/COFF/build-info.ll
===
--- llvm/test/DebugInfo/COFF/build-info.ll
+++ llvm/test/DebugInfo/COFF/build-info.ll
@@ -10,6 +10,16 @@
 
 ; CHECK: {{.*}} | S_BUILDINFO [size = 8] BuildId = `[[INFO_IDX]]`
 
+; Test path is canalized to windows backslash style when output object file 
name
+; is not starting with '/'.
+; RUN: rm -rf %t-dir
+; RUN: mkdir %t-dir
+; RUN: cd %t-dir
+; RUN: llc -filetype=obj -mtriple i686-pc-windows-msvc %s -o ../build-info.o
+; RUN: llvm-readobj --codeview ../build-info.o | FileCheck %s 
--check-prefix=OBJ
+
+; OBJ: ObjectName: ..\build-info.o
+
 ; ModuleID = 'D:\src\scopes\foo.cpp'
 source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,11 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+llvm::sys::path::is_absolute(PathRef, llvm::sys::path::Style::posix)
+? llvm::sys::path::Style::posix
+: llvm::sys::path::Style::windows_backslash;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g 
%s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g 
%s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}clang/test/CodeGen\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}clang/test/CodeGen/debug-info-slash.c"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
   auto  = CGM.getCodeGenOpts();
+  const LangOptions  = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions  = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;


Index: llvm/test/DebugInfo/COFF/build-info.ll

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-03-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

I'm trying to add the test case from: 
https://github.com/llvm/llvm-project/issues/45481#issuecomment-981028897, but 
lit test fails in `` not found.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-03-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 509098.
zequanwu added a comment.

- Handle invalid start location.
- Add a test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147073/new/

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/invalid_location.cpp


Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++20 -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//now because 'T{}' doesn't have a valid end location for now.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)
+
+// CHECK-NEXT:   File 0, 14:5 -> 14:6 = #0
+// CHECK-NEXT:   Branch,File 0, 14:5 -> 14:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 14:8 -> 14:9 = #2
+// CHECK-NEXT:   File 0, 14:9 -> 14:10 = #2
+// CHECK-NEXT:   File 0, 14:13 -> 14:14 = (#0 - #2)
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If the either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
@@ -716,7 +724,8 @@
 
 // The statement may be spanned by an expansion. Make sure we handle a file
 // exit out of this expansion before moving to the next statement.
-if (SM.isBeforeInTranslationUnit(StartLoc, S->getBeginLoc()))
+if (StartLoc.isValid() &&
+SM.isBeforeInTranslationUnit(StartLoc, S->getBeginLoc()))
   MostRecentLocation = EndLoc;
 
 return ExitCount;
@@ -891,6 +900,8 @@
   /// Find a valid gap range between \p AfterLoc and \p BeforeLoc.
   std::optional findGapAreaBetween(SourceLocation AfterLoc,
 SourceLocation BeforeLoc) {
+if (AfterLoc.isInvalid() || BeforeLoc.isInvalid())
+  return std::nullopt;
 // If AfterLoc is in function-like macro, use the right parenthesis
 // location.
 if (AfterLoc.isMacroID()) {


Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-03-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: hans, shafik, rsmith, MaggieYi, gulfem.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

https://github.com/llvm/llvm-project/issues/45481 exposes an issue that an
expression/statement can have valid start location but invalid end location in
some situations.

This confuses `CounterCoverageMappingBuilder` when popping a region from region
stack as if the end location is a macro or include location.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If the either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If the either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146164: Fix nomerge attribute not working with __builtin_trap().

2023-03-16 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D146164#4200414 , @rsmith wrote:

> FYI: this attribute appears to not work on (at least) x86 and arm currently, 
> because the backend also does some merging: https://godbolt.org/z/d43M83oax

Thanks for reporting it. I'll look into it later.




Comment at: clang/lib/CodeGen/CGExpr.cpp:3626-3627
   }
-
+  if (InNoMergeAttributedStmt)
+TrapCall->addFnAttr(llvm::Attribute::NoMerge);
   return TrapCall;

rsmith wrote:
> There are 496 calls to `Builder.CreateCall` in clang's `CodeGen`. Do they all 
> need this change? If not, how can we be confident we've found all the ones 
> that do? (From a quick check, at least MSVC's `__fastfail` builtin seems like 
> it would also benefit from this handling.)
> 
> Would it be reasonable to make clang's `CGBuilder` do this for every call 
> instruction we create?
I think all of them (builtin functions) should have that change, theoretically, 
because they are not different from `__builtin_trap`. Probably we should change 
the `Builder.CreateCall` to take a list of attributes that will be added to 
that CallInst and update all calls to `CreateCall`. Is there any easier 
approach?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146164/new/

https://reviews.llvm.org/D146164

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


[PATCH] D146164: Fix nomerge attribute not working with __builtin_trap().

2023-03-16 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/test/CodeGen/attr-nomerge.cpp:44
+
+  [[clang::nomerge]] __builtin_trap();
 }

hans wrote:
> Maybe do __debugbreak() too since that's also mentioned on the debug.
The `__debugbreak()` is also emitted from `EmitTrapCall()`. So, just add a test 
case for `__debugbreak()`. 



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6856
   return;
 }
 TargetLowering::ArgListTy Args;

hans wrote:
> Do we need to handle this "else" branch too?
> 
> Or would it make sense to do the nomerge check in the caller of 
> `visitIntrinsicCall` instead?
Setting CLI.NoMerge instead of setting DAG.getRoot(), because it later somehow 
replace the root with another instruction which causes the call instruction to 
lose the attribute. 

Added a test case for else branch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146164/new/

https://reviews.llvm.org/D146164

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


[PATCH] D146164: Fix nomerge attribute not working with __builtin_trap().

2023-03-16 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 505837.
zequanwu marked 3 inline comments as done.
zequanwu added a comment.

- Add test case for __debugbreak().
- Handle named trap instructions and add test case for it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146164/new/

https://reviews.llvm.org/D146164

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/X86/nomerge.ll

Index: llvm/test/CodeGen/X86/nomerge.ll
===
--- llvm/test/CodeGen/X86/nomerge.ll
+++ llvm/test/CodeGen/X86/nomerge.ll
@@ -22,7 +22,72 @@
 
 declare dso_local void @bar()
 
+define void @nomerge_trap(i32 %i) {
+entry:
+  switch i32 %i, label %if.end3 [
+i32 5, label %if.then
+i32 7, label %if.then2
+  ]
+
+if.then:
+  tail call void @llvm.trap() #0
+  unreachable
+
+if.then2:
+  tail call void @llvm.trap() #0
+  unreachable
+
+if.end3:
+  tail call void @llvm.trap() #0
+  unreachable
+}
+
+declare dso_local void @llvm.trap()
+
+define void @nomerge_debugtrap(i32 %i) {
+entry:
+  switch i32 %i, label %if.end3 [
+i32 5, label %if.then
+i32 7, label %if.then2
+  ]
+
+if.then:
+  tail call void @llvm.debugtrap() #0
+  unreachable
+
+if.then2:
+  tail call void @llvm.debugtrap() #0
+  unreachable
+
+if.end3:
+  tail call void @llvm.debugtrap() #0
+  unreachable
+}
+
+define void @nomerge_named_debugtrap(i32 %i) {
+entry:
+  switch i32 %i, label %if.end3 [
+i32 5, label %if.then
+i32 7, label %if.then2
+  ]
+
+if.then:
+  tail call void @llvm.debugtrap() #1
+  unreachable
+
+if.then2:
+  tail call void @llvm.debugtrap() #1
+  unreachable
+
+if.end3:
+  tail call void @llvm.debugtrap() #1
+  unreachable
+}
+
+declare dso_local void @llvm.debugtrap()
+
 attributes #0 = { nomerge }
+attributes #1 = { nomerge "trap-func-name"="trap_func" }
 
 ; CHECK-LABEL: foo:
 ; CHECK: # %bb.0: # %entry
@@ -34,3 +99,33 @@
 ; CHECK: callq bar
 ; CHECK: .LBB0_4: # %if.end3
 ; CHECK: jmp bar # TAILCALL
+
+; CHECK-LABEL: nomerge_trap:
+; CHECK:  # %bb.0: # %entry
+; CHECK:  # %bb.1: # %entry
+; CHECK:  # %bb.2: # %if.then
+; CHECK-NEXT: ud2
+; CHECK-NEXT: LBB1_3: # %if.then2
+; CHECK-NEXT: ud2
+; CHECK-NEXT: .LBB1_4: # %if.end3
+; CHECK-NEXT: ud2
+
+; CHECK-LABEL: nomerge_debugtrap:
+; CHECK:  # %bb.0: # %entry
+; CHECK:  # %bb.1: # %entry
+; CHECK:  # %bb.2: # %if.then
+; CHECK-NEXT: int3
+; CHECK-NEXT: LBB2_3: # %if.then2
+; CHECK-NEXT: int3
+; CHECK-NEXT: .LBB2_4: # %if.end3
+; CHECK-NEXT: int3
+
+; CHECK-LABEL: nomerge_named_debugtrap:
+; CHECK:  # %bb.0: # %entry
+; CHECK:  # %bb.1: # %entry
+; CHECK:  # %bb.2: # %if.then
+; CHECK-NEXT: callq trap_func@PLT
+; CHECK-NEXT: LBB3_3: # %if.then2
+; CHECK-NEXT: callq trap_func@PLT
+; CHECK-NEXT: .LBB3_4: # %if.end3
+; CHECK-NEXT: callq trap_func@PLT
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -6849,6 +6849,8 @@
 break;
   default: llvm_unreachable("unknown trap intrinsic");
   }
+  DAG.addNoMergeSiteInfo(DAG.getRoot().getNode(),
+ I.hasFnAttr(Attribute::NoMerge));
   return;
 }
 TargetLowering::ArgListTy Args;
@@ -6865,7 +6867,7 @@
 DAG.getExternalSymbol(TrapFuncName.data(),
   TLI.getPointerTy(DAG.getDataLayout())),
 std::move(Args));
-
+CLI.NoMerge = I.hasFnAttr(Attribute::NoMerge);
 std::pair Result = TLI.LowerCallTo(CLI);
 DAG.setRoot(Result.second);
 return;
Index: clang/test/CodeGen/attr-nomerge.cpp
===
--- clang/test/CodeGen/attr-nomerge.cpp
+++ clang/test/CodeGen/attr-nomerge.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm %s -fms-extensions -o - | FileCheck %s
 
 class A {
 public:
@@ -40,6 +40,9 @@
 
   A *newA = new B();
   delete newA;
+
+  [[clang::nomerge]] __builtin_trap();
+  [[clang::nomerge]] __debugbreak();
 }
 
 int g(int i);
@@ -93,6 +96,8 @@
 // CHECK: load ptr, ptr
 // CHECK: %[[AG:.*]] = load ptr, ptr
 // CHECK-NEXT: call void %[[AG]](ptr {{.*}}) #[[ATTR1]]
+// CHECK: call void @llvm.trap() #[[ATTR0]]
+// CHECK: call void @llvm.debugtrap() #[[ATTR0]]
 // CHECK: call void  @_ZN1AD1Ev(ptr {{.*}}) #[[ATTR1]]
 
 // CHECK-DAG: attributes #[[ATTR0]] = {{{.*}}nomerge{{.*}}}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3623,7 +3623,8 @@
   CGM.getCodeGenOpts().TrapFuncName);
 TrapCall->addFnAttr(A);

[PATCH] D146164: Fix nomerge attribute not working with __builtin_trap().

2023-03-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: hans, craig.topper.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

1. It fixes the problem that `llvm.trap()` not getting the nomerge attribute.
2. It sets nomerge flag for the node if the instruction has nomerge arrtibute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146164

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/X86/nomerge.ll

Index: llvm/test/CodeGen/X86/nomerge.ll
===
--- llvm/test/CodeGen/X86/nomerge.ll
+++ llvm/test/CodeGen/X86/nomerge.ll
@@ -22,6 +22,28 @@
 
 declare dso_local void @bar()
 
+define void @nomerge_trap(i32 %i) {
+entry:
+  switch i32 %i, label %if.end3 [
+i32 5, label %if.then
+i32 7, label %if.then2
+  ]
+
+if.then:
+  tail call void @llvm.trap() #0
+  br label %if.end3
+
+if.then2:
+  tail call void @llvm.trap() #0
+  br label %if.end3
+
+if.end3:
+  tail call void @llvm.trap() #0
+  ret void
+}
+
+declare dso_local void @llvm.trap()
+
 attributes #0 = { nomerge }
 
 ; CHECK-LABEL: foo:
@@ -34,3 +56,16 @@
 ; CHECK: callq bar
 ; CHECK: .LBB0_4: # %if.end3
 ; CHECK: jmp bar # TAILCALL
+
+; CHECK-LABEL: nomerge_trap:
+; CHECK:  # %bb.0: # %entry
+; CHECK:  # %bb.1: # %entry
+; CHECK:  # %bb.2: # %if.then
+; CHECK-NEXT: ud2
+; CHECK-NEXT: ud2
+; CHECK-NEXT: retq
+; CHECK-NEXT: .LBB1_3: # %if.then2
+; CHECK-NEXT: ud2
+; CHECK-NEXT: .LBB1_4: # %if.end3
+; CHECK-NEXT: ud2
+; CHECK-NEXT: retq
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -6833,22 +6833,25 @@
 StringRef TrapFuncName =
 I.getAttributes().getFnAttr("trap-func-name").getValueAsString();
 if (TrapFuncName.empty()) {
+  SDValue Node;
   switch (Intrinsic) {
   case Intrinsic::trap:
-DAG.setRoot(DAG.getNode(ISD::TRAP, sdl, MVT::Other, getRoot()));
+Node = DAG.getNode(ISD::TRAP, sdl, MVT::Other, getRoot());
 break;
   case Intrinsic::debugtrap:
-DAG.setRoot(DAG.getNode(ISD::DEBUGTRAP, sdl, MVT::Other, getRoot()));
+Node = DAG.getNode(ISD::DEBUGTRAP, sdl, MVT::Other, getRoot());
 break;
   case Intrinsic::ubsantrap:
-DAG.setRoot(DAG.getNode(
+Node = DAG.getNode(
 ISD::UBSANTRAP, sdl, MVT::Other, getRoot(),
 DAG.getTargetConstant(
 cast(I.getArgOperand(0))->getZExtValue(), sdl,
-MVT::i32)));
+MVT::i32));
 break;
   default: llvm_unreachable("unknown trap intrinsic");
   }
+  DAG.addNoMergeSiteInfo(Node.getNode(), I.hasFnAttr(Attribute::NoMerge));
+  DAG.setRoot(Node);
   return;
 }
 TargetLowering::ArgListTy Args;
Index: clang/test/CodeGen/attr-nomerge.cpp
===
--- clang/test/CodeGen/attr-nomerge.cpp
+++ clang/test/CodeGen/attr-nomerge.cpp
@@ -40,6 +40,8 @@
 
   A *newA = new B();
   delete newA;
+
+  [[clang::nomerge]] __builtin_trap();
 }
 
 int g(int i);
@@ -93,6 +95,7 @@
 // CHECK: load ptr, ptr
 // CHECK: %[[AG:.*]] = load ptr, ptr
 // CHECK-NEXT: call void %[[AG]](ptr {{.*}}) #[[ATTR1]]
+// CHECK: call void @llvm.trap() #[[ATTR0]]
 // CHECK: call void  @_ZN1AD1Ev(ptr {{.*}}) #[[ATTR1]]
 
 // CHECK-DAG: attributes #[[ATTR0]] = {{{.*}}nomerge{{.*}}}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3623,7 +3623,8 @@
   CGM.getCodeGenOpts().TrapFuncName);
 TrapCall->addFnAttr(A);
   }
-
+  if (InNoMergeAttributedStmt)
+TrapCall->addFnAttr(llvm::Attribute::NoMerge);
   return TrapCall;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144371: [LLVM-COV] Fix an issue: a statement after calling 'assert()' function is wrongly marked as 'not executed'

2023-03-01 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu accepted this revision.
zequanwu added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144371/new/

https://reviews.llvm.org/D144371

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


[PATCH] D144371: [LLVM-COV] Fix an issue: a statement after calling 'assert()' function is wrongly marked as 'not executed'

2023-02-28 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Thanks for fixing it.

Just one comment.




Comment at: clang/test/CoverageMapping/terminate-statements.cpp:335
+  ( true ? void (0) : abort() );  // CHECK: Gap,File 0, [[@LINE]]:33 -> 
[[@LINE+1]]:3 = #1
+  ( false ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:34 -> 
[[@LINE+1]]:3 = #2
+  return 0;

For completeness, can you add following two tests:
```
( true ? abort() : void (0) );
( false ? abort() : void (0) );
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144371/new/

https://reviews.llvm.org/D144371

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


[PATCH] D138326: [CodeView] Don't generate dummy unnamed strcut/class/union type.

2022-12-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Landed at: https://reviews.llvm.org/rGbb5bcddcdbc151119f449be2d1e0d90f2e9c4258. 
Forgot to add the "Revision" line.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138326/new/

https://reviews.llvm.org/D138326

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-22 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D137217#3945136 , @glandium wrote:

> Still broken:
>
>   task 2022-11-22T22:09:00.912Z] /usr/lib/llvm-11/bin/clang++ 
> --sysroot=/builds/worker/fetches/sysroot -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE 
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
> -Itools/gold -I/builds/worker/fetches/llvm-project/llvm/tools/gold -Iinclude 
> -I/builds/worker/fetches/llvm-project/llvm/include -fPIC 
> -fvisibility-inlines-hidden -Werror=date-time 
> -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
> -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
> -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
> -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
> -ffunction-sections -fdata-sections -O3 -DNDEBUG -fPIC  -fno-exceptions 
> -fno-rtti -std=c++17 -MD -MT 
> tools/gold/CMakeFiles/LLVMgold.dir/gold-plugin.cpp.o -MF 
> tools/gold/CMakeFiles/LLVMgold.dir/gold-plugin.cpp.o.d -o 
> tools/gold/CMakeFiles/LLVMgold.dir/gold-plugin.cpp.o -c 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp
>   [task 2022-11-22T22:09:00.912Z] 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp::18: 
> error: no viable conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'llvm::AddStreamFn' (aka 
> 'function> (unsigned int, const 
> llvm::Twine &)>')
>   [task 2022-11-22T22:09:00.912Z]   check(Lto->run(AddStream, Cache));
>   [task 2022-11-22T22:09:00.912Z]  ^
>   [task 2022-11-22T22:09:00.912Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:421:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
>   [task 2022-11-22T22:09:00.912Z]   function(nullptr_t) noexcept
>   [task 2022-11-22T22:09:00.912Z]   ^
>   [task 2022-11-22T22:09:00.912Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:432:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'const 
> std::function std::default_delete>> (unsigned int, const 
> llvm::Twine &)> &' for 1st argument
>   [task 2022-11-22T22:09:00.912Z]   function(const function& __x);
>   [task 2022-11-22T22:09:00.912Z]   ^
>   [task 2022-11-22T22:09:00.912Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:441:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'std::function std::default_delete>> (unsigned int, const 
> llvm::Twine &)> &&' for 1st argument
>   [task 2022-11-22T22:09:00.912Z]   function(function&& __x) noexcept : 
> _Function_base()
>   [task 2022-11-22T22:09:00.913Z]   ^
>   [task 2022-11-22T22:09:00.913Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:465:2:
>  note: candidate template ignored: substitution failure [with _Functor = 
> (lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20), 
> $1 = void]: no type named 'type' in 'std::result_of<(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20) 
> &(unsigned int, const llvm::Twine &)>'
>   [task 2022-11-22T22:09:00.913Z] function(_Functor);
>   [task 2022-11-22T22:09:00.913Z] ^
>   [task 2022-11-22T22:09:00.913Z] 
> /builds/worker/fetches/llvm-project/llvm/include/llvm/LTO/LTO.h:278:25: note: 
> passing argument to parameter 'AddStream' here
>   [task 2022-11-22T22:09:00.913Z]   Error run(AddStreamFn AddStream, 
> FileCache Cache = nullptr);
>   [task 2022-11-22T22:09:00.913Z] ^
>   [task 2022-11-22T22:09:00.913Z] 1 error generated.

Oh, sorry, I missed another place. Hope this 
 will fix 
it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-22 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D137217#3944952 , @glandium wrote:

> This broke the gold plugin:
>
>   [task 2022-11-22T21:03:29.486Z] 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1108:19: 
> error: no matching function for call to 'localCache'
>   [task 2022-11-22T21:03:29.486Z] Cache = check(localCache("ThinLTO", 
> "Thin", options::cache_dir, AddBuffer));
>   [task 2022-11-22T21:03:29.487Z]   ^~
>   [task 2022-11-22T21:03:29.487Z] 
> /builds/worker/fetches/llvm-project/llvm/include/llvm/Support/Caching.h:72:21:
>  note: candidate function not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1102:20)' 
> to 'llvm::AddBufferFn' (aka 'function &, std::unique_ptr)>') for 4th argument
>   [task 2022-11-22T21:03:29.487Z] Expected localCache(
>   [task 2022-11-22T21:03:29.488Z] ^
>   [task 2022-11-22T21:03:29.488Z] 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1110:18: 
> error: no viable conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'llvm::AddStreamFn' (aka 
> 'function> (unsigned int, const 
> llvm::Twine &)>')
>   [task 2022-11-22T21:03:29.488Z]   check(Lto->run(AddStream, Cache));
>   [task 2022-11-22T21:03:29.488Z]  ^
>   [task 2022-11-22T21:03:29.488Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:421:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
>   [task 2022-11-22T21:03:29.488Z]   function(nullptr_t) noexcept
>   [task 2022-11-22T21:03:29.488Z]   ^
>   [task 2022-11-22T21:03:29.489Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:432:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'const 
> std::function std::default_delete>> (unsigned int, const 
> llvm::Twine &)> &' for 1st argument
>   [task 2022-11-22T21:03:29.489Z]   function(const function& __x);
>   [task 2022-11-22T21:03:29.489Z]   ^
>   [task 2022-11-22T21:03:29.489Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:441:7:
>  note: candidate constructor not viable: no known conversion from '(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' 
> to 'std::function std::default_delete>> (unsigned int, const 
> llvm::Twine &)> &&' for 1st argument
>   [task 2022-11-22T21:03:29.489Z]   function(function&& __x) noexcept : 
> _Function_base()
>   [task 2022-11-22T21:03:29.489Z]   ^
>   [task 2022-11-22T21:03:29.489Z] 
> /builds/worker/fetches/sysroot/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:465:2:
>  note: candidate template ignored: substitution failure [with _Functor = 
> (lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20), 
> $1 = void]: no type named 'type' in 'std::result_of<(lambda at 
> /builds/worker/fetches/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20) 
> &(unsigned int, const llvm::Twine &)>'
>   [task 2022-11-22T21:03:29.489Z] function(_Functor);
>   [task 2022-11-22T21:03:29.489Z] ^
>   [task 2022-11-22T21:03:29.489Z] 
> /builds/worker/fetches/llvm-project/llvm/include/llvm/LTO/LTO.h:278:25: note: 
> passing argument to parameter 'AddStream' here
>   [task 2022-11-22T21:03:29.489Z]   Error run(AddStreamFn AddStream, 
> FileCache Cache = nullptr);
>   [task 2022-11-22T21:03:29.489Z] ^
>   [task 2022-11-22T21:03:29.489Z] 2 errors generated.

Thanks for noticing. I have fixed at 
https://reviews.llvm.org/rG10a43c4641c20e0a50edc0ff99915c837a507cc1. 
Unfortunately, this patch is reverted right before that fix pushed. I relanded 
this at https://reviews.llvm.org/rG84be92d26fcb1ddad533c0c614a79a81c59f795d.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-22 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Relanded here 
 to match 
api changes at https://reviews.llvm.org/D135590


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-22 Thread Zequan Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG531ed6d5aa65: [LTO][COFF] Use bitcode file names in lto 
native object file names. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D137217?vs=477014=477246#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,9 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream =
+  [&](size_t Task,
+  const Twine ) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +422,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, const Twine ,
+   std::unique_ptr MB) {
+*AddStream(Task, ModuleName)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,9 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream =
+[&](size_t Task,
+const Twine ) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -26,9 +26,9 @@
 
 using namespace llvm;
 
-Expected llvm::localCache(Twine CacheNameRef,
- Twine TempFilePrefixRef,
- Twine CacheDirectoryPathRef,
+Expected llvm::localCache(const Twine ,
+ const Twine ,
+ const Twine ,
  AddBufferFn AddBuffer) {
 
   // Create local copies which are safely captured-by-copy in lambdas
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ const Twine ) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ModuleName(ModuleName), Task(Task) {}
 
   ~CacheStream() {
 // TODO: Manually commit rather than using non-trivial destructor,
@@ -133,11 +135,12 @@
  TempFile.TmpName + " to " + ObjectPathName + ": " +
  

[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-21 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 477014.
zequanwu added a comment.

Update `Twine` argument to `const Twine&`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,9 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream =
+  [&](size_t Task,
+  const Twine ) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +422,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, const Twine ,
+   std::unique_ptr MB) {
+*AddStream(Task, ModuleName)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,9 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream =
+[&](size_t Task,
+const Twine ) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -26,9 +26,9 @@
 
 using namespace llvm;
 
-Expected llvm::localCache(Twine CacheNameRef,
- Twine TempFilePrefixRef,
- Twine CacheDirectoryPathRef,
+Expected llvm::localCache(const Twine ,
+ const Twine ,
+ const Twine ,
  AddBufferFn AddBuffer) {
 
   // Create local copies which are safely captured-by-copy in lambdas
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ const Twine ) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ModuleName(ModuleName), Task(Task) {}
 
   ~CacheStream() {
 // TODO: Manually commit rather than using non-trivial destructor,
@@ -133,11 +135,12 @@
  TempFile.TmpName + " to " + ObjectPathName + ": " +
  toString(std::move(E)) + "\n");
 
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
   }
 };
 
-return 

[PATCH] D138326: [CodeView] Don't generate dummy unnamed strcut/class/union type.

2022-11-18 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D138326#3938128 , @rnk wrote:

> Since Clang creates the member list and only adds types for the benefit of 
> codeview, should we change clang instead?

Yes, that's something clang does only for codeview, changed in clang side. It 
will still emit type info for unnamed records but not for anonymous records.




Comment at: llvm/test/DebugInfo/COFF/nested-types.ll:214
+; CHECK-NEXT:   }
 ; CHECK-NEXT:   NestedType {
 ; CHECK-NEXT: TypeLeafKind: LF_NESTTYPE (0x1510)

rnk wrote:
> So the test shows that we don't have NestedType records for unnamed unions & 
> structs, right?
Updated. We want NestedType records for unnamed unions & structs, but not for 
anonymous unions & structs. That's what MSVC does.
```
 0x1004 | LF_FIELDLIST [size = 168]
- LF_MEMBER [name = `i1`, Type = 0x0074 (int), offset = 0, attrs = 
public]
- LF_NESTTYPE [name = ``, parent = 
0x1002]
- LF_MEMBER [name = `unnamed_union`, Type = 0x1002, offset = 4, 
attrs = public]
- LF_MEMBER [name = `i3`, Type = 0x0074 (int), offset = 8, attrs = 
public]
- LF_NESTTYPE [name = ``, parent = 
0x1003]
- LF_MEMBER [name = `unnamed_struct`, Type = 0x1003, offset = 12, 
attrs = public]
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138326/new/

https://reviews.llvm.org/D138326

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


[PATCH] D138326: [CodeView] Don't generate dummy unnamed strcut/class/union type.

2022-11-18 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 476621.
zequanwu added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Reverted previous change and change clang side so that it doesn't emit nested 
anonymous record type when emitting code-view.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138326/new/

https://reviews.llvm.org/D138326

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp


Index: clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
@@ -5,6 +5,11 @@
   typedef int InnerTypedef;
   enum { InnerEnumerator = 2 };
   struct InnerStruct { };
+
+  union { int i1; };
+  union { int i2; } unnamed_union;
+  struct { int i3; };
+  struct { int i4; } unnamed_struct;
 };
 HasNested f;
 
@@ -12,7 +17,7 @@
 // CHECK: ![[HASNESTED:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "HasNested",
 // CHECK-SAME: elements: ![[MEMBERS:[0-9]+]],
 //
-// CHECK: ![[MEMBERS]] = !{![[INNERENUM]], ![[INNERTYPEDEF:[0-9]+]], 
![[UNNAMEDENUM:[0-9]+]], ![[INNERSTRUCT:[0-9]+]]}
+// CHECK: ![[MEMBERS]] = !{![[INNERENUM]], ![[INNERTYPEDEF:[0-9]+]], 
![[UNNAMEDENUM:[0-9]+]], ![[INNERSTRUCT:[0-9]+]], ![[ANONYMOUS_UNION:[0-9]+]], 
![[UNNAMED_UNION_TYPE:[0-9]+]], ![[UNNAMED_UNION:[0-9]+]], 
![[ANONYMOUS_STRUCT:[0-9]+]], ![[UNNAMED_STRUCT_TYPE:[0-9]+]], 
![[UNNAMED_STRUCT:[0-9]+]]}
 //
 // CHECK: ![[INNERTYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: 
"InnerTypedef", scope: ![[HASNESTED]]{{.*}})
 //
@@ -23,3 +28,31 @@
 //
 // CHECK: ![[INNERSTRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, 
name: "InnerStruct"
 // CHECK-SAME: flags: DIFlagFwdDecl
+
+// CHECK: ![[ANONYMOUS_UNION]] = !DIDerivedType(tag: DW_TAG_member, 
+// CHECK-SAME: baseType: ![[ANONYMOUS_UNION_TYPE:[0-9]+]]
+// CHECK: ![[ANONYMOUS_UNION_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_union_type,
+// CHECK-SAME: elements: ![[ANONYMOUS_UNION_MEMBERS:[0-9]+]], identifier: 
".?AT@HasNested@@")
+// CHECK: ![[ANONYMOUS_UNION_MEMBERS]] = !{![[ANONYMOUS_UNION_MEMBER:[0-9]+]]}
+// CHECK: ![[ANONYMOUS_UNION_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i1"
+
+// CHECK: ![[UNNAMED_UNION_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_union_type, name: ""
+// CHECK-SAME: elements: ![[UNNAMED_UNION_MEMBERS:[0-9]+]], identifier: 
".?AT@HasNested@@")
+// CHECK: ![[UNNAMED_UNION_MEMBERS]] = !{![[UNNAMED_UNION_MEMBER:[0-9]+]]}
+// CHECK: ![[UNNAMED_UNION_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, name: 
"i2"
+// CHECK: ![[UNNAMED_UNION]] = !DIDerivedType(tag: DW_TAG_member, name: 
"unnamed_union"
+// CHECK-SAME: baseType: ![[UNNAMED_UNION_TYPE]]
+
+// CHECK: ![[ANONYMOUS_STRUCT]] = !DIDerivedType(tag: DW_TAG_member
+// CHECK-SAME: baseType: ![[ANONYMOUS_STRUCT_TYPE:[0-9]+]]
+// CHECK: ![[ANONYMOUS_STRUCT_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type
+// CHECK-SAME: elements: ![[ANONYMOUS_STRUCT_MEMBERS:[0-9]+]], identifier: 
".?AU@HasNested@@")
+// CHECK: ![[ANONYMOUS_STRUCT_MEMBERS]] = 
!{![[ANONYMOUS_STRUCT_MEMBER:[0-9]+]]}
+// CHECK: ![[ANONYMOUS_STRUCT_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i3"
+
+// CHECK: ![[UNNAMED_STRUCT_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: ""
+// CHECK-SAME: elements: ![[UNNAMED_STRUCT_MEMBERS:[0-9]+]], identifier: 
".?AU@HasNested@@")
+// CHECK: ![[UNNAMED_STRUCT_MEMBERS]] = !{![[UNNAMED_STRUCT_MEMBER:[0-9]+]]}
+// CHECK: ![[UNNAMED_STRUCT_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i4"
+// CHECK: ![[UNNAMED_STRUCT]] = !DIDerivedType(tag: DW_TAG_member, name: 
"unnamed_struct"
+// CHECK-SAME: baseType: ![[UNNAMED_STRUCT_TYPE]]
\ No newline at end of file
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1652,10 +1652,15 @@
   } else if (CGM.getCodeGenOpts().EmitCodeView) {
 // Debug info for nested types is included in the member list only for
 // CodeView.
-if (const auto *nestedType = dyn_cast(I))
+if (const auto *nestedType = dyn_cast(I)) {
+  // MSVC doesn't generate nested type for anonymous struct/union.
+  if (isa(I) &&
+  cast(I)->isAnonymousStructOrUnion())
+continue;
   if (!nestedType->isImplicit() &&
   nestedType->getDeclContext() == record)
 CollectRecordNestedType(nestedType, elements);
+}
   }
   }
 }


Index: clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
+++ 

[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-16 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: lld/COFF/LTO.cpp:238
+  sys::path::append(path, directory,
+outputFileBaseName + ".lto." + baseName);
+  sys::path::remove_dots(path, true);

tejohnson wrote:
> MaskRay wrote:
> > What if two input bitcode files have the same basename, e.g. `dir1/a.obj` 
> > and `dir2/a.obj`?
> I think that should be ok as the output file path created here includes the 
> directory. So you should get dir1/a.out.lto.a.obj and dir2/a.out.lto.a.obj.
Yes, you will get dir1/a.out.lto.a.obj and dir2/a.out.lto.a.obj.



Comment at: lld/COFF/LTO.cpp:229
+StringRef ltoObjName;
+if (bitcodeFilePath == "ld-temp.o") {
+  ltoObjName =

tejohnson wrote:
> MaskRay wrote:
> > MaskRay wrote:
> > > tejohnson wrote:
> > > > zequanwu wrote:
> > > > > tejohnson wrote:
> > > > > > This case should always be i==0 I think?
> > > > > IIUC, "ld-temp.o" is the name of combined module. Do you mean there 
> > > > > will be only 1 combined module and it will always be the first task?
> > > > Yes. So you don't need the handling for i==0 in the name in this case 
> > > > (you could probably assert that i==0).
> > > This looks like a hack. `assert(i == 0)` will fail with 
> > > `-opt:lldltopartitions=2`: `buf[1]` will be called `ld-temp.o` as well.
> > > 
> > > In addition, if an input bitcode file is called `ld-temp.o` (for some 
> > > reason they don't use `.obj`, just `ld-temp.o`), `assert(i == 0)` will 
> > > fail as well.
> > I guess `if (i < config->ltoPartitions)` may fix the issue.
> Ah ok, forgot about the lto partitions case. Sorry, @zequanwu, looks like you 
> will need to go back to your old handling that appends i if it is non-zero.
I reverted this part back. Since input bitcode file can be called `ld-temp.o`, 
i could be any number smaller than maxTasks, removed assertion. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-16 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 475895.
zequanwu marked an inline comment as done.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,8 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task,
+   Twine ModuleName) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +421,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, Twine ModuleName,
+   std::unique_ptr MB) {
+*AddStream(Task, ModuleName)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,9 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream =
+[&](size_t Task,
+Twine ModuleName) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ Twine ModuleName) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ModuleName(ModuleName), Task(Task) {}
 
   ~CacheStream() {
 // TODO: Manually commit rather than using non-trivial destructor,
@@ -133,11 +135,12 @@
  TempFile.TmpName + " to " + ObjectPathName + ": " +
  toString(std::move(E)) + "\n");
 
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
   }
 };
 
-return [=](size_t Task) -> Expected> {
+return [=](size_t Task, Twine ModuleName)
+   -> Expected> {
   // Create the cache directory if not already done. Doing this lazily
   // ensures the filesystem isn't mutated until the cache is.
   if (std::error_code EC = sys::fs::create_directories(
@@ -158,7 +161,8 @@
   // This CacheStream will move the temporary file into the cache when done.
   return std::make_unique(
   

[PATCH] D137806: [AST] Fix class layout when using external layout under MS ABI.

2022-11-16 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29c92879171d: [AST] Fix class layout when using external 
layout under MS ABI. (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D137806?vs=474623=475880#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137806/new/

https://reviews.llvm.org/D137806

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
  clang/test/CodeGenCXX/override-layout-virtual-base.cpp

Index: clang/test/CodeGenCXX/override-layout-virtual-base.cpp
===
--- clang/test/CodeGenCXX/override-layout-virtual-base.cpp
+++ clang/test/CodeGenCXX/override-layout-virtual-base.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck --check-prefix=SIMPLE  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck %s
 
 struct S1 {
   int a;
@@ -8,14 +9,48 @@
   virtual void foo() {}
 };
 
-// CHECK: Type: struct S3
-// CHECK:   FieldOffsets: [128]
+// SIMPLE: Type: struct S3
+// SIMPLE:   FieldOffsets: [64]
 struct S3 : S2 {
   char b;
 };
 
+struct S4 {
+};
+
+struct S5 : S4 {
+  virtual void foo() {}
+};
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK:   0 | struct S2
+// CHECK-NEXT:  0 |   (S2 vftable pointer)
+// CHECK-NEXT:  8 |   (S2 vbtable pointer)
+// CHECK-NEXT:  8 |   struct S1 (virtual base)
+// CHECK-NEXT:  8 | int a
+// CHECK-NEXT:| [sizeof=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+// CHECK:  *** Dumping AST Record Layout
+// CHECK:   0 | struct S3
+// CHECK-NEXT:  0 |   struct S2 (primary base)
+// CHECK-NEXT:  0 | (S2 vftable pointer)
+// CHECK-NEXT:  8 | (S2 vbtable pointer)
+// CHECK-NEXT:  8 |   char b
+// CHECK-NEXT: 16 |   struct S1 (virtual base)
+// CHECK-NEXT: 16 | int a
+// CHECK-NEXT:| [sizeof=24, align=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=8]
+// CHECK:  *** Dumping AST Record Layout
+// CHECK:   0 | struct S5
+// CHECK-NEXT:  0 |   (S5 vftable pointer)
+// CHECK-NEXT:  0 |   struct S4 (base) (empty)
+// CHECK-NEXT:| [sizeof=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+
 void use_structs() {
   S1 s1s[sizeof(S1)];
   S2 s2s[sizeof(S2)];
   S3 s3s[sizeof(S3)];
+  S4 s4s[sizeof(S4)];
+  S5 s5s[sizeof(S5)];
 }
Index: clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
===
--- clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
+++ clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
@@ -6,3 +6,11 @@
   Size:64
   Alignment:64
   FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct S5
+
+Layout: 
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2027,7 +2027,7 @@
 
   // The align if the field is not packed. This is to check if the attribute
   // was unnecessary (-Wpacked).
-  CharUnits UnpackedFieldAlign = FieldAlign; 
+  CharUnits UnpackedFieldAlign = FieldAlign;
   CharUnits PackedFieldAlign = CharUnits::One();
   CharUnits UnpackedFieldOffset = FieldOffset;
   CharUnits OriginalFieldAlign = UnpackedFieldAlign;
@@ -3081,10 +3081,9 @@
 VBPtrOffset += Offset;
 
   if (UseExternalLayout) {
-// The class may have no bases or fields, but still have a vfptr
-// (e.g. it's an interface class). The size was not correctly set before
-// in this case.
-if (FieldOffsets.empty() && Bases.empty())
+// The class may have size 0 and a vfptr (e.g. it's an interface class). The
+// size was not correctly set before in this case.
+if (Size.isZero())
   Size += Offset;
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 475538.
zequanwu marked 2 inline comments as done.
zequanwu added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,8 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task,
+   Twine ModuleName) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +421,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, Twine ModuleName,
+   std::unique_ptr MB) {
+*AddStream(Task, ModuleName)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,9 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream =
+[&](size_t Task,
+Twine ModuleName) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ Twine ModuleName) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ModuleName(ModuleName), Task(Task) {}
 
   ~CacheStream() {
 // TODO: Manually commit rather than using non-trivial destructor,
@@ -133,11 +135,12 @@
  TempFile.TmpName + " to " + ObjectPathName + ": " +
  toString(std::move(E)) + "\n");
 
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
   }
 };
 
-return [=](size_t Task) -> Expected> {
+return [=](size_t Task, Twine ModuleName)
+   -> Expected> {
   // Create the cache directory if not already done. Doing this lazily
   // ensures the filesystem isn't mutated until the cache is.
   if (std::error_code EC = sys::fs::create_directories(
@@ -158,7 +161,8 @@
   // This CacheStream will move the temporary file into the cache when done.
   return std::make_unique(
   

[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1104
 
-  auto AddStream = [&](size_t Task) {
+  auto AddStream = [&](size_t Task, Twine File) {
 return std::make_unique(std::move(OS),

tejohnson wrote:
> I think you might need to mark the new parameter as unused here and in other 
> cases where it isn't used via LLVM_ATTRIBUTE_UNUSED, to avoid build warnings 
> - I can't recall how strictly that is enforced.
LLVM_ATTRIBUTE_UNUSED is used to suppress unused functions. For unused 
parameter, I don't see any build warnings when compiling with this patch. I 
feel like it's very common to have unused parameter. 



Comment at: lld/COFF/LTO.cpp:229
+StringRef ltoObjName;
+if (bitcodeFilePath == "ld-temp.o") {
+  ltoObjName =

tejohnson wrote:
> This case should always be i==0 I think?
IIUC, "ld-temp.o" is the name of combined module. Do you mean there will be 
only 1 combined module and it will always be the first task?



Comment at: lld/COFF/LTO.cpp:245
+  saveBuffer(buf[i].second, ltoObjName);
 ret.push_back(make(ctx, MemoryBufferRef(objBuf, ltoObjName)));
   }

tejohnson wrote:
> The above changes affect both the MemoryBufferRef name as well as the 
> saveTemps output file name. I assume the change to the former is what is 
> required for PDB, is that correct?
Yes, it changes both the MemoryBufferRef and the saveTemps output file name 
otherwise the saveTemps output file name won't match with the the names in pdb. 
The former is what's written into PDB.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 475296.
zequanwu marked 2 inline comments as done.
zequanwu added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,8 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task,
+   Twine ModuleName) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +421,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, Twine ModuleName,
+   std::unique_ptr MB) {
+*AddStream(Task, ModuleName)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,9 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream =
+[&](size_t Task,
+Twine ModuleName) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ Twine ModuleName) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ModuleName(ModuleName), Task(Task) {}
 
   ~CacheStream() {
 // TODO: Manually commit rather than using non-trivial destructor,
@@ -133,11 +135,12 @@
  TempFile.TmpName + " to " + ObjectPathName + ": " +
  toString(std::move(E)) + "\n");
 
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, ModuleName, std::move(*MBOrErr));
   }
 };
 
-return [=](size_t Task) -> Expected> {
+return [=](size_t Task, Twine ModuleName)
+   -> Expected> {
   // Create the cache directory if not already done. Doing this lazily
   // ensures the filesystem isn't mutated until the cache is.
   if (std::error_code EC = sys::fs::create_directories(
@@ -158,7 +161,8 @@
   // This CacheStream will move the temporary file into the cache when done.
   return std::make_unique(
   

[PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137217/new/

https://reviews.llvm.org/D137217

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


[PATCH] D137806: [AST] Fix class layout when using external layout under MS ABI.

2022-11-10 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/test/CodeGenCXX/override-layout-virtual-base.cpp:25-43
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct S2
+// CHECK-NEXT:  0 |   (S2 vftable pointer)
+// CHECK-NEXT:  8 |   (S2 vbtable pointer)
+// CHECK-NEXT:  8 |   struct S1 (virtual base)
+// CHECK-NEXT:  8 | int a
+// CHECK-NEXT:| [sizeof=8, align=8,

Pasted -fdump-record-layout result below before this change as reference:
```
*** Dumping AST Record Layout
 0 | struct S1
 0 |   int a
   | [sizeof=4, align=4,
   |  nvsize=4, nvalign=4]

*** Dumping AST Record Layout
 0 | struct S2
 0 |   (S2 vftable pointer)
 8 |   (S2 vbtable pointer)
16 |   struct S1 (virtual base)
16 | int a
   | [sizeof=8, align=8,
   |  nvsize=16, nvalign=8]

*** Dumping AST Record Layout
 0 | struct S3
 0 |   struct S2 (primary base)
 0 | (S2 vftable pointer)
 8 | (S2 vbtable pointer)
16 |   char b
24 |   struct S1 (virtual base)
24 | int a
   | [sizeof=32, align=8,
   |  nvsize=24, nvalign=8]

*** Dumping AST Record Layout
 0 | struct S4 (empty)
   | [sizeof=1, align=1,
   |  nvsize=0, nvalign=1]

*** Dumping AST Record Layout
 0 | struct S5
 0 |   (S5 vftable pointer)
 0 |   struct S4 (base) (empty)
   | [sizeof=8, align=8,
   |  nvsize=0, nvalign=8]
```




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137806/new/

https://reviews.llvm.org/D137806

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


[PATCH] D137806: [AST] Fix class layout when using external layout under MS ABI.

2022-11-10 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added a reviewer: rnk.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137806

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
  clang/test/CodeGenCXX/override-layout-virtual-base.cpp

Index: clang/test/CodeGenCXX/override-layout-virtual-base.cpp
===
--- clang/test/CodeGenCXX/override-layout-virtual-base.cpp
+++ clang/test/CodeGenCXX/override-layout-virtual-base.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck --check-prefix=SIMPLE  %s
+// RUN: %clang_cc1 -w -triple=x86_64-pc-win32 -fms-compatibility -fdump-record-layouts -foverride-record-layout=%S/Inputs/override-layout-virtual-base.layout %s | FileCheck %s
 
 struct S1 {
   int a;
@@ -8,14 +9,49 @@
   virtual void foo() {}
 };
 
-// CHECK: Type: struct S3
-// CHECK:   FieldOffsets: [128]
+// SIMPLE: Type: struct S3
+// SIMPLE:   FieldOffsets: [64]
 struct S3 : S2 {
   char b;
 };
 
+struct S4 {
+};
+
+struct S5 : S4 {
+  virtual void foo() {}
+};
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct S2
+// CHECK-NEXT:  0 |   (S2 vftable pointer)
+// CHECK-NEXT:  8 |   (S2 vbtable pointer)
+// CHECK-NEXT:  8 |   struct S1 (virtual base)
+// CHECK-NEXT:  8 | int a
+// CHECK-NEXT:| [sizeof=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+// CHECK-NEXT:
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct S3
+// CHECK-NEXT:  0 |   struct S2 (primary base)
+// CHECK-NEXT:  0 | (S2 vftable pointer)
+// CHECK-NEXT:  8 | (S2 vbtable pointer)
+// CHECK-NEXT:  8 |   char b
+// CHECK-NEXT: 16 |   struct S1 (virtual base)
+// CHECK-NEXT: 16 | int a
+// CHECK-NEXT:| [sizeof=24, align=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=8]
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct S5
+// CHECK-NEXT:  0 |   (S5 vftable pointer)
+// CHECK-NEXT:  0 |   struct S4 (base) (empty)
+// CHECK-NEXT:| [sizeof=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+
 void use_structs() {
   S1 s1s[sizeof(S1)];
   S2 s2s[sizeof(S2)];
   S3 s3s[sizeof(S3)];
+  S4 s4s[sizeof(S4)];
+  S5 s5s[sizeof(S5)];
 }
Index: clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
===
--- clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
+++ clang/test/CodeGenCXX/Inputs/override-layout-virtual-base.layout
@@ -6,3 +6,11 @@
   Size:64
   Alignment:64
   FieldOffsets: []>
+
+*** Dumping AST Record Layout
+Type: struct S5
+
+Layout: 
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2027,7 +2027,7 @@
 
   // The align if the field is not packed. This is to check if the attribute
   // was unnecessary (-Wpacked).
-  CharUnits UnpackedFieldAlign = FieldAlign; 
+  CharUnits UnpackedFieldAlign = FieldAlign;
   CharUnits PackedFieldAlign = CharUnits::One();
   CharUnits UnpackedFieldOffset = FieldOffset;
   CharUnits OriginalFieldAlign = UnpackedFieldAlign;
@@ -3081,10 +3081,9 @@
 VBPtrOffset += Offset;
 
   if (UseExternalLayout) {
-// The class may have no bases or fields, but still have a vfptr
-// (e.g. it's an interface class). The size was not correctly set before
-// in this case.
-if (FieldOffsets.empty() && Bases.empty())
+// The class may have size 0 and a vfptr (e.g. it's an interface class). The
+// size was not correctly set before in this case.
+if (Size.isZero())
   Size += Offset;
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >