Skip to content

Conversation

@swalk-qualcomm
Copy link
Contributor

There was an unprotected use of a function that could return the null pointer.

Steve Walk added 2 commits January 6, 2025 10:41
…ualcomm/llvm-project into hexagonLoopIdiomDebugFault

Change-Id: I9d17ce248173eba081decc1938592dfb213a4298
@github-actions
Copy link

github-actions bot commented Jan 6, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2025

@llvm/pr-subscribers-backend-hexagon

Author: None (swalk-qualcomm)

Changes

There was an unprotected use of a function that could return the null pointer.


Full diff: https://github.com/llvm/llvm-project/pull/121828.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+2)
  • (added) llvm/test/CodeGen/Hexagon/loopIdiom.ll (+78)
diff --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
index 46a8ab395d32bd..991ee5b1cbaa53 100644
--- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
@@ -1796,6 +1796,8 @@ bool PolynomialMultiplyRecognize::recognize() {
     IterCount = CV->getValue()->getZExtValue() + 1;
 
   Value *CIV = getCountIV(LoopB);
+  if (CIV == nullptr)
+    return false;
   ParsedValues PV;
   Simplifier PreSimp;
   PV.IterCount = IterCount;
diff --git a/llvm/test/CodeGen/Hexagon/loopIdiom.ll b/llvm/test/CodeGen/Hexagon/loopIdiom.ll
new file mode 100644
index 00000000000000..aa8532fd9ddbd0
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/loopIdiom.ll
@@ -0,0 +1,78 @@
+; RUN: opt -debug -S -march=hexagon -O2  < %s | FileCheck %s
+; REQUIRES: asserts
+; CHECK: define dso_local void @complexMultAccum
+; ModuleID = 'loopIdiom.c'
+source_filename = "loopIdiom.c"
+target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
+target triple = "hexagon"
+
+; Function Attrs: noinline nounwind
+define dso_local void @complexMultAccum(i32 noundef %n) #0 {
+entry:
+  %n.addr = alloca i32, align 4
+  %run_c_code = alloca i8, align 1
+  %run_asm_code = alloca i8, align 1
+  %iOutter = alloca i32, align 4
+  %iOutter1 = alloca i32, align 4
+  store i32 %n, ptr %n.addr, align 4
+  store i8 1, ptr %run_c_code, align 1
+  store i8 0, ptr %run_asm_code, align 1
+  %0 = load i8, ptr %run_c_code, align 1
+  %tobool = icmp ne i8 %0, 0
+  br i1 %tobool, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  store i32 0, ptr %iOutter, align 4
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %if.then
+  %1 = load i32, ptr %iOutter, align 4
+  %cmp = icmp slt i32 %1, 2
+  br i1 %cmp, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %2 = load i32, ptr %iOutter, align 4
+  %inc = add nsw i32 %2, 1
+  store i32 %inc, ptr %iOutter, align 4
+  br label %for.cond, !llvm.loop !3
+
+for.end:                                          ; preds = %for.cond
+  store i32 0, ptr %iOutter1, align 4
+  br label %for.cond2
+
+for.cond2:                                        ; preds = %for.inc5, %for.end
+  %3 = load i32, ptr %iOutter1, align 4
+  %cmp3 = icmp slt i32 %3, 2
+  br i1 %cmp3, label %for.body4, label %for.end7
+
+for.body4:                                        ; preds = %for.cond2
+  br label %for.inc5
+
+for.inc5:                                         ; preds = %for.body4
+  %4 = load i32, ptr %iOutter1, align 4
+  %inc6 = add nsw i32 %4, 1
+  store i32 %inc6, ptr %iOutter1, align 4
+  br label %for.cond2, !llvm.loop !5
+
+for.end7:                                         ; preds = %for.cond2
+  br label %if.end
+
+if.end:                                           ; preds = %for.end7, %entry
+  ret void
+}
+
+attributes #0 = { noinline nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv79" "target-features"="+v79,-long-calls" "unsafe-fp-math"="true" }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"frame-pointer", i32 2}
+!2 = !{!"QuIC LLVM Hexagon Clang version 19.0 Private Release: hexagon-clang-190"}
+!3 = distinct !{!3, !4}
+!4 = !{!"llvm.loop.mustprogress"}
+!5 = distinct !{!5, !4}
+

@androm3da androm3da requested review from androm3da and iajbar January 6, 2025 20:39
Copy link
Member

@androm3da androm3da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your commits are authored by and committed by [email protected]. At some point we might be permitted to use those email addresses but for now I think we still need to use our @quicinc.com ones.

Comment on lines 4 to 6
; ModuleID = 'loopIdiom.c'
source_filename = "loopIdiom.c"
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are not needed.

@swalk-qualcomm
Copy link
Contributor Author

Updated per comments above.

@androm3da
Copy link
Member

LGTM but @iajbar should approve.

@iajbar iajbar merged commit 75781fa into llvm:main Jan 8, 2025
7 checks passed
@github-actions
Copy link

github-actions bot commented Jan 8, 2025

@swalk-qualcomm Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 8, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-ubuntu running on as-builder-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/187/builds/3616

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
RUN: at line 1: rm -rf /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp && mkdir -p /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp
+ rm -rf /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp
+ mkdir -p /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp
RUN: at line 2: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-mc --triple=loongarch64 --filetype=obj -o /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s
+ /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-mc --triple=loongarch64 --filetype=obj -o /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s
RUN: at line 3: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-jitlink --noexec               --abs external_data=0xdeadbeef               --abs external_func=0xcafef00d               --check /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o
+ /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-jitlink --noexec --abs external_data=0xdeadbeef --abs external_func=0xcafef00d --check /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o
llvm-jitlink: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h:285: llvm::orc::SymbolStringPool::~SymbolStringPool(): Assertion `Pool.empty() && "Dangling references at pool destruction time"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-jitlink --noexec --abs external_data=0xdeadbeef --abs external_func=0xcafef00d --check /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o
 #0 0x0000555b9e6064b4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x0000555b9e6068d5 PrintStackTraceSignalHandler(void*) /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x0000555b9e603d25 llvm::sys::RunSignalHandlers() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x0000555b9e605d4c SignalHandler(int) /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fe957ee9520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fe957f3d9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x00007fe957ee9476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007fe957ecf7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00007fe957ecf71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #9 0x00007fe957ee0e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000555b9d32d0de llvm::orc::SymbolStringPool::~SymbolStringPool() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h:287:1
#11 0x0000555b9d3ab618 void __gnu_cxx::new_allocator<llvm::orc::SymbolStringPool>::destroy<llvm::orc::SymbolStringPool>(llvm::orc::SymbolStringPool*) /usr/include/c++/11/ext/new_allocator.h:168:17
#12 0x0000555b9d3aa4f3 void std::allocator_traits<std::allocator<llvm::orc::SymbolStringPool>>::destroy<llvm::orc::SymbolStringPool>(std::allocator<llvm::orc::SymbolStringPool>&, llvm::orc::SymbolStringPool*) /usr/include/c++/11/bits/alloc_traits.h:539:2
#13 0x0000555b9d3a8959 std::_Sp_counted_ptr_inplace<llvm::orc::SymbolStringPool, std::allocator<llvm::orc::SymbolStringPool>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() /usr/include/c++/11/bits/shared_ptr_base.h:529:7
#14 0x0000555b9d35791c std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /usr/include/c++/11/bits/shared_ptr_base.h:180:48
#15 0x0000555b9d339227 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() /usr/include/c++/11/bits/shared_ptr_base.h:706:7
#16 0x0000555b9d32e248 std::__shared_ptr<llvm::orc::SymbolStringPool, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() /usr/include/c++/11/bits/shared_ptr_base.h:1154:7
#17 0x0000555b9d32e268 std::shared_ptr<llvm::orc::SymbolStringPool>::~shared_ptr() /usr/include/c++/11/bits/shared_ptr.h:122:11
#18 0x0000555b9e442238 llvm::orc::ExecutorProcessControl::~ExecutorProcessControl() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp:27:1
#19 0x0000555b9e444f11 llvm::orc::SelfExecutorProcessControl::~SelfExecutorProcessControl() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:467:7
#20 0x0000555b9e444f50 llvm::orc::SelfExecutorProcessControl::~SelfExecutorProcessControl() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:467:7
#21 0x0000555b9d36707c std::default_delete<llvm::orc::ExecutorProcessControl>::operator()(llvm::orc::ExecutorProcessControl*) const /usr/include/c++/11/bits/unique_ptr.h:86:7
#22 0x0000555b9d3490b4 std::unique_ptr<llvm::orc::ExecutorProcessControl, std::default_delete<llvm::orc::ExecutorProcessControl>>::~unique_ptr() /usr/include/c++/11/bits/unique_ptr.h:362:8
#23 0x0000555b9e26c3fd llvm::orc::ExecutionSession::~ExecutionSession() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp:1600:1
#24 0x0000555b9d309620 llvm::Session::~Session() /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/tools/llvm-jitlink/llvm-jitlink.cpp:1033:1
#25 0x0000555b9d3674e4 std::default_delete<llvm::Session>::operator()(llvm::Session*) const /usr/include/c++/11/bits/unique_ptr.h:85:2
#26 0x0000555b9d371690 std::__uniq_ptr_impl<llvm::Session, std::default_delete<llvm::Session>>::reset(llvm::Session*) /usr/include/c++/11/bits/unique_ptr.h:183:7
#27 0x0000555b9d355175 std::unique_ptr<llvm::Session, std::default_delete<llvm::Session>>::reset(llvm::Session*) /usr/include/c++/11/bits/unique_ptr.h:457:7
#28 0x0000555b9d316fb5 main /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/tools/llvm-jitlink/llvm-jitlink.cpp:2586:13
#29 0x00007fe957ed0d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007fe957ed0e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000555b9d304be5 _start (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-jitlink+0x7f9be5)
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.script: line 3: 4010168 Aborted                 (core dumped) /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llvm-jitlink --noexec --abs external_data=0xdeadbeef --abs external_func=0xcafef00d --check /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_loongarch64_relocations.s /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/ExecutionEngine/JITLink/LoongArch/Output/ELF_loongarch64_relocations.s.tmp/elf_reloc.o

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants