[llvm-bugs] [Bug 51410] New: Incorrect optimization results cause branch redirection errors.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 9 00:07:54 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51410

            Bug ID: 51410
           Summary: Incorrect optimization results cause branch
                    redirection errors.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: 2077213809 at qq.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

I have the following test case. The problem occurs on the ARM platform. It
seems that the problem is caused by Clang optimization. I expected to enter the
return 1 branch of the foo function, but actually enter return 0, which is
normal only when O2 optimization occurs.

clang --target=arm-none-eabi -O2 test.c 

#include <stdio.h>
typedef struct {
  void *pPtAddr;
  unsigned int uwPtSize;
} Node;

unsigned int foo(unsigned int ucPtNo, Node *para) {
  char *pcPtEnd;

  pcPtEnd = (char *)para->pPtAddr + para->uwPtSize;

  if ((unsigned int)para->pPtAddr >= (unsigned int)pcPtEnd) {

    return 1;
  }
  printf("unexcetion print %p %p\n", para->pPtAddr, pcPtEnd);
  return 0;
}

int main() {
  Node para;
  para.pPtAddr = (void *)0xffffffff;
  para.uwPtSize = 0xfff;
  int res = foo(32, &para);
  printf("%d\n", res);
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210809/b0d74667/attachment.html>


More information about the llvm-bugs mailing list