[PATCH] D115670: Implement some constexpr vector unary operators, fix boolean-ops

Qiongsi Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 21 12:14:33 PST 2021


qiongsiwu1 added subscribers: bmahjour, anhtuyen, qiongsiwu1.
qiongsiwu1 added a comment.

Hi everyone! We are encountering crashes in some of our `altivec` test cases due to this change. `clang` crashes when we have an instance of a `struct` or `union` type, and we assign the result of a unary operator `++` or `--` with a vector operand to a field of the instance. If we are assigning the result to just a vector type, the compiler does not crash.

Here is a reproducer. To reproduce the crash, use command `clang -target powerpc-unknown-unknown -maltivec small.c`.

  // small.c
  #include <stdio.h>
  
  // struct type
  typedef struct result
  {
      vector signed short result_vec;
  } RESULT;
  
  vector signed short op_nine = { 9, 9, 9, 9, 9, 9, 9, 9 };
  
  int main() {
      // Instance of the struct type
      RESULT r;
  
      // This line below crashes - we are assigning the result of the unary operator to a struct field. 
      r.result_vec = ++op_nine;
      for (int i = 0; i < 8; ++i) {
          printf("%d\t", r.result_vec[i]);
      }
      printf("\n");
  
      // This case works fine. The compiler does not crash. 
      /*vector signed short op_10 = ++op_nine;
      for (int i = 0; i < 8; ++i) {
          printf("%d\t", op_10[i]);
      }
      printf("\n"); */
  }

We discovered this on AIX and we can reproduce this on Linux on Power. The issue is reproducible on Intel based Macs as well. Here is a stack dump from MacOS.

  Assertion failed: (isVector() && "Invalid accessor"), function getVectorLength, file /Users/qiongsiwu/workspace/community/llvm-project/clang/include/clang/AST/APValue.h, line 498.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.	Program arguments: /Users/qiongsiwu/workspace/community/llvm-project/build/bin/clang-14 -cc1 -triple powerpc-unknown-unknown -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu ppc -target-feature +altivec -mfloat-abi hard -debugger-tuning=gdb -target-linker-version 650.9 -fcoverage-compilation-dir=/Users/qiongsiwu/workspace/13359 -resource-dir /Users/qiongsiwu/workspace/community/llvm-project/build/lib/clang/14.0.0 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ -fdebug-compilation-dir=/Users/qiongsiwu/workspace/13359 -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/gh/5hw84m4x2hv4csmhpp8y02680000gn/T/small-e9e02b.o -x c small.c
  1.	small.c:23:5: current parser token 'return'
  2.	small.c:12:12: parsing function body 'main'
  3.	small.c:12:12: in compound statement ('{}')
  Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
  0  clang-14                 0x0000000107d8d1f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
  1  clang-14                 0x0000000107d8bfb8 llvm::sys::RunSignalHandlers() + 248
  2  clang-14                 0x0000000107d8d840 SignalHandler(int) + 272
  3  libsystem_platform.dylib 0x00007ff80662fe2d _sigtramp + 29
  4  libsystem_platform.dylib 0x00007ff7ba7632d0 _sigtramp + 18446744072435741888
  5  libsystem_c.dylib        0x00007ff806566d10 abort + 123
  6  libsystem_c.dylib        0x00007ff8065660be err + 0
  7  clang-14                 0x000000010c208443 (anonymous namespace)::VectorExprEvaluator::VisitUnaryOperator(clang::UnaryOperator const*) (.cold.13) + 35
  8  clang-14                 0x000000010a40b1d7 (anonymous namespace)::VectorExprEvaluator::VisitUnaryOperator(clang::UnaryOperator const*) + 2375

On AIX, the compiler can produce the following AST during `EvaluateVector` before the crash.

  [EvaluateVector]
  BinaryOperator 0x11173e148 '__vector short' '='
  |-MemberExpr 0x11173e0e0 '__vector short' lvalue .result_vec 0x111739f40
  | `-DeclRefExpr 0x11173a5a0 'RESULT':'struct result' lvalue Var 0x11173a520 'r' 'RESULT':'struct result'
  `-UnaryOperator 0x11173e130 '__vector short' prefix '++'
    `-DeclRefExpr 0x11173e110 '__vector short' lvalue Var 0x11173a070 'op_nine' '__vector short'
  [EvaluateVector]
  UnaryOperator 0x11173e130 '__vector short' prefix '++'
  `-DeclRefExpr 0x11173e110 '__vector short' lvalue Var 0x11173a070 'op_nine' '__vector short'

The compiler crashes when trying to deal with `0x11173a070`. It is expecting a vector kind (`APValue::ValueKind::Vector`), but the actual kind is `APValue::ValueKind::LValue`, and the compiler crashes inside `SubExprValue.getVectorLength()`.

Could you help us take a look? Thanks a lot! FYI @bmahjour @anhtuyen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115670



More information about the cfe-commits mailing list