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

main.cpp: invalid conversion from int to enum #1355

Closed
waebbl opened this issue Nov 5, 2018 · 2 comments
Closed

main.cpp: invalid conversion from int to enum #1355

waebbl opened this issue Nov 5, 2018 · 2 comments

Comments

@waebbl
Copy link

waebbl commented Nov 5, 2018

Hi, I'm trying to compile ispc HEAD using cmake, llvm-6.0.1 and gcc-7.3.0 in release mode on Gentoo Linux.
In main.cpp I get the error:

var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp: In function ‘int main(int, char**)’:
/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp:669:19: error: invalid conversion from ‘int’ to ‘Module::OutputFlags’ [-fpermissive]
             flags |= Module::GeneratePIC;
             ~~~~~~^~~~~~~~~
/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp:685:17: error: invalid conversion from ‘int’ to ‘Module::OutputFlags’ [-fpermissive]
           flags |= Module::GenerateFlatDeps;
           ~~~~~~^~~~~~~~~
/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp:688:62: error: invalid conversion from ‘int’ to ‘Module::OutputFlags’ [-fpermissive]
           flags |= Module::GenerateMakeRuleForDeps | Module::OutputDepsToStdout;
                                                              ^~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp:773:13: error: invalid conversion from ‘int’ to ‘Module::OutputFlags’ [-fpermissive]
       flags &= ~Module::OutputDepsToStdout;
       ~~~~~~^~~~~~~~~~
/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999/src/main.cpp:787:13: error: invalid conversion from ‘int’ to ‘Module::OutputFlags’ [-fpermissive]
       flags &= Module::GenerateMakeRuleForDeps;
       ~~~~~~^~~~~~~~~

Applying the patch

diff --git a/src/module.h b/src/module.h
index 26dfe4a8..3cab756e 100644
--- a/src/module.h
+++ b/src/module.h
@@ -106,7 +106,7 @@ public:
                       HostStub  /** generate host-side offload stubs */
     };
 
-    enum OutputFlags { NoFlags = 0,
+    enum OutputFlags : int { NoFlags = 0,
                        GeneratePIC = 0x1,
                        GenerateFlatDeps = 0x2,         /** Dependencies will be output as a flat list. */
                        GenerateMakeRuleForDeps = 0x4,  /** Dependencies will be output in a make rule format instead of a flat list. */

makes it compile, but then I get a linker error to undefined llvm symbols:

CMakeFiles/ispc.dir/src/llvmutil.cpp.o: In function `lDumpValue(llvm::Value*, std::set<llvm::Value*, std::less<llvm::Value*>, std::allocator<llvm::Value*> >&)':
llvmutil.cpp:(.text+0x2f28): undefined reference to `llvm::Value::dump() const'
llvmutil.cpp:(.text+0x2fbd): undefined reference to `llvm::Value::dump() const'
CMakeFiles/ispc.dir/src/opt.cpp.o: In function `DebugPass::runOnModule(llvm::Module&)':
opt.cpp:(.text+0x47a): undefined reference to `llvm::Module::dump() const'
CMakeFiles/ispc.dir/src/opt.cpp.o: In function `IsCompileTimeConstantPass::runOnBasicBlock(llvm::BasicBlock&)':
opt.cpp:(.text+0x1d35): undefined reference to `llvm::Value::dump() const'
opt.cpp:(.text+0x1e2c): undefined reference to `llvm::Value::dump() const'
CMakeFiles/ispc.dir/src/opt.cpp.o: In function `ReplacePseudoMemoryOpsPass::runOnBasicBlock(llvm::BasicBlock&)':
opt.cpp:(.text+0x364e): undefined reference to `llvm::Value::dump() const'
opt.cpp:(.text+0x3764): undefined reference to `llvm::Value::dump() const'
CMakeFiles/ispc.dir/src/opt.cpp.o: In function `InstructionSimplifyPass::runOnBasicBlock(llvm::BasicBlock&)':
opt.cpp:(.text+0x3b88): undefined reference to `llvm::Value::dump() const'
CMakeFiles/ispc.dir/src/opt.cpp.o:opt.cpp:(.text+0x3c8d): more undefined references to `llvm::Value::dump() const' follow
CMakeFiles/ispc.dir/src/opt.cpp.o: In function `Optimize(llvm::Module*, int)':
opt.cpp:(.text+0xf648): undefined reference to `llvm::Module::dump() const'
opt.cpp:(.text+0xf68f): undefined reference to `llvm::Module::dump() const'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ispc.dir/build.make:2220: ispc] Error 1
make[2]: Leaving directory '/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999_build'
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/ispc.dir/all] Error 2
make[1]: Leaving directory '/var/tmp/portage/dev-lang/ispc-9999/work/ispc-9999_build'
make: *** [Makefile:130: all] Error 2

When searching for this, I found a question on stackoverflow, which states, that this might be due to llvm-5 not exporting these functions when it's compiled in release mode. Maybe this might also be true for later versions of llvm. I haven't recompiled llvm yet in debug mode to verify this.
For the question, see https://stackoverflow.com/questions/46367910/llvm-5-0-linking-error-with-llvmmoduledump#

@dbabokin
Copy link
Collaborator

dbabokin commented Nov 5, 2018

First issue is due to gcc being too strict on language. It's known issue, we probably should fix that, but primary recommended compiler is clang (don't want to elaborate on this here), so it was not top priority to fix.

The second issue (linking) is because your LLVM is not built with proper flags. ISPC relies on LLVM and it needs to be built "the right way". It might occasionally work with "stock" LLVM builds, but there are multiple known issues. The right way to build LLVM is to use "alloy.py" script (alloy.py -b --version=6.0 --selfbuild). And use clang after that for ISPC build.

Also LLVm 5.0 is probably better candidate at the moment if you are looking for something stable to start with.

We do need better documentation for developers hacking on ISPC. Thanks for bringing attention to this question.

@waebbl
Copy link
Author

waebbl commented Nov 7, 2018

Thanks for your feedback. Using llvm-5, I was able to build the package.

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

2 participants