Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Arithemetic #367

Open
anniezfy opened this issue Nov 2, 2023 · 2 comments
Open

Complex Arithemetic #367

anniezfy opened this issue Nov 2, 2023 · 2 comments

Comments

@anniezfy
Copy link
Contributor

anniezfy commented Nov 2, 2023

Hi~ I have encountered with few problems regarding with Complex arithmetic.
I have tried to convert the following code snippet to MLIR representation.

@anniezfy
Copy link
Contributor Author

anniezfy commented Nov 2, 2023

#include <complex.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{ 
    complex<double> c1(2.0, 3.0);
    complex<double> c2(1.0, 2.0);
    complex<double> sum = c1 + c2;
    
} 

However ,the program is crashed with a diagnostic error , I barely do not know where is exact fail point?

/home/shichen/Polygeist/build/bin/cgeist -S -function="main" main.cpp
cgeist: /home/shichen/Polygeist/tools/cgeist/Lib/ValueCategory.cc:45: mlir::Value ValueCategory::getValue(mlir::Location, mlir::OpBuilder&) const: Assertion `mt.getShape().size() == 1 && "must have shape 1"' 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/shichen/Polygeist/build/bin/cgeist -S -function=main main.cpp

  1. parser at end of file
    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 cgeist 0x000055ed19a1d2d2
    1 cgeist 0x000055ed19a1d6ee
    2 cgeist 0x000055ed19a1ab3b
    3 cgeist 0x000055ed19a1cb6a
    4 libc.so.6 0x00007f1ab58a6520
    5 libc.so.6 0x00007f1ab58fa9fc pthread_kill + 300
    6 libc.so.6 0x00007f1ab58a6476 raise + 22
    7 libc.so.6 0x00007f1ab588c7f3 abort + 211
    8 libc.so.6 0x00007f1ab588c71b
    9 libc.so.6 0x00007f1ab589de96
    10 cgeist 0x000055ed17d9d69c
    11 cgeist 0x000055ed17c299b2
    12 cgeist 0x000055ed17cba47d
    13 cgeist 0x000055ed17cb90e9
    14 cgeist 0x000055ed17c801ca
    15 cgeist 0x000055ed17d5bae8
    16 cgeist 0x000055ed17c80529
    17 cgeist 0x000055ed17c16348
    18 cgeist 0x000055ed17c39aa4
    19 cgeist 0x000055ed17c3aa14
    20 cgeist 0x000055ed22c0f60d
    21 cgeist 0x000055ed1c651b6e
    22 cgeist 0x000055ed1c651418
    23 cgeist 0x000055ed17c3fad6
    24 cgeist 0x000055ed17c4125c
    25 libc.so.6 0x00007f1ab588dd90
    26 libc.so.6 0x00007f1ab588de40 __libc_start_main + 128
    27 cgeist 0x000055ed17c12725

@anniezfy
Copy link
Contributor Author

anniezfy commented Nov 2, 2023

Thanks to @ftynse tips, Polygeist supports the C_Complex type. However, there are still unresolved issues. I have tested several input cases, including those with only imaginary components, only real components, and both imaginary and real components. Here is diagnostic error information:

#include <complex.h>

int main(void)
{ 
   double complex z = 3.0;  // only real part
} 
 
FunctionDecl 0x563e883524d0 <main.c:3:1, line:6:1> line:3:5 main 'int (void)'
`-CompoundStmt 0x563e8833f6f0 <line:4:1, line:6:1>
  `-DeclStmt 0x563e8833f6d8 <line:5:4, col:26>
    `-VarDecl 0x563e883525b8 <col:4, col:23> col:19 z '_Complex double' cinit
      `-ImplicitCastExpr 0x563e8833f6c0 <col:23> '_Complex double' <FloatingRealToComplex>
        `-FloatingLiteral 0x563e8833f6a0 <col:23> 'double' 3.000000e+00
ImplicitCastExpr 0x563e8833f6c0 '_Complex double' <FloatingRealToComplex>
`-FloatingLiteral 0x563e8833f6a0 'double' 3.000000e+00
cgeist: /home/shichen/Polygeist/tools/cgeist/Lib/clang-mlir.cc:4440: ValueCategory MLIRScanner::VisitCastExpr(clang::CastExpr*): Assertion `0 && "unhandled cast"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

The first case emits clang-AST tree and mention code fail point

#include <complex.h>

int main(void)
{ 
   double complex z = 3.0*I;  // only imaginary part
} 
 
(base) shichen@shichen-lab:~/zhaofangyu$ /home/shichen/Polygeist/build/bin/cgeist -S main.c -function=main
cgeist: /home/shichen/Polygeist/tools/cgeist/Lib/clang-mlir.cc:124: ValueCategory MLIRScanner::getComplexPartRef(mlir::Location, mlir::Value, int): Assertion `shape.size() == 2' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

In the second case, console only print code fail point

#include <complex.h>

int main(void)
{ 
   double _Complex z = 2.0+3.0*I;  // only real part
} 
(base) shichen@shichen-lab:~/zhaofangyu$ /home/shichen/Polygeist/build/bin/cgeist -S main.c -function=main
cgeist: /home/shichen/Polygeist/tools/cgeist/Lib/clang-mlir.cc:124: ValueCategory MLIRScanner::getComplexPartRef(mlir::Location, mlir::Value, int): Assertion `shape.size() == 2' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
In the second case, console only print code [fail point ](https://github.com/llvm/Polygeist/blob/main/tools/cgeist/Lib/clang-mlir.cc#L124C1-L124C31)

At last, console emit the same error as previous one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant