Coder Social home page Coder Social logo

trailofbits / constexpr-everything Goto Github PK

View Code? Open in Web Editor NEW
243.0 39.0 14.0 41 KB

Rewrite C++ code to automatically apply `constexpr` where possible

Home Page: https://blog.trailofbits.com/2019/06/27/use-constexpr-for-faster-smaller-and-safer-code/

License: Apache License 2.0

CMake 13.96% C++ 86.04%
clang c-plus-plus llvm clang-ti quality secur

constexpr-everything's Introduction

constexpr-everything

Build Status

A libclang based project to automatically rewrite as much code as possible to be evaluated in constexpr contexts.

Requires LLVM (and Clang) 9, 10, or 11.

Building

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .

Usage

Build a project with a compilation database, run constexpr-everything on the source files.

Read more about the tool at https://blog.trailofbits.com/2019/06/27/use-constexpr-for-faster-smaller-and-safer-code/.

License

constexpr-everything is licensed and distributed under the Apache 2.0 license. Contact us if you're looking for an exception to the terms.

constexpr-everything's People

Contributors

ams21 avatar disconnect3d avatar patrickelectric avatar sigiesec avatar withzombies avatar woodruffw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

constexpr-everything's Issues

Error with c std library

$ constexpr-everything src/configuration.cpp
In file included from /path/to/src/configuration.cpp:3:
In file included from /path/to/src/include/configuration.h:5:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/map:60:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/stl_tree.h:63:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/stl_algobase.h:67:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/stl_iterator.h:81:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/new:41:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/exception:147:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/exception_ptr.h:38:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/cxxabi_init_exception.h:38:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
         ^~~~~~~~~~
1 error generated.
Error while processing /path/to/src/configuration.cpp.
$ constexpr-everything --version
LLVM (http://llvm.org/):
  LLVM version 11.1.0
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: znver1

Compile Errors. Wrong llvm/clang version?

Unfortunately my compilation fails with constexpr-everything/main.cpp:232:11: error: class clang::FunctionDecl’ has no member named ‘setConstexpr’; did you mean ‘isConstexpr’?`.

Can you please specify the llvm version you used to compile constexpr-everything?

I tried with llvm commit ed499a36b67cf46cbf66052cfe374c80a595f1c1.

Error when running

Compiled following instructions from README.

When running I get the following error:

: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

I'm using manjaro linux. Tried compiling both with clang 8.0 and gcc 8.3.

Build error

Hi,
I'm using ubuntu 19.04 with latest llvm & clang installed in docker environment.
And I got these error...

root@4de3a3fc188c /c/build# cmake --build .
[ 50%] Building CXX object CMakeFiles/constexpr-everything.dir/main.cpp.o
/constexpr-everything/main.cpp:3:10: fatal error: clang/AST/RecursiveASTVisitor.h: No such file or directory
 #include "clang/AST/RecursiveASTVisitor.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/constexpr-everything.dir/build.make:63: CMakeFiles/constexpr-everything.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/constexpr-everything.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
root@4de3a3fc188c /c/build#

Support newer LLVM versions

We currently support LLVM 9, 10, and 11. We should consider dropping one or two of those and supporting LLVM 12 and 13.

I took a quick stab at this in #15, but gave up since it wasn't as simple as a few API changes.

Cannot build with LLVM 8.0.0 or 9.0.1

When building with LLVM 8.0.0, CMake is happy with that:

-- The CXX compiler identification is GNU 9.2.1
-- Check for working CXX compiler: /usr/lib64/ccache/c++
-- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LLVM 8.0.0
-- Using LLVMConfig.cmake in: /usr/lib64/cmake/llvm
-- Configuring done
-- Generating done
-- Build files have been written to: /home/simon/src/constexpr-everything/build

but it won't build:

[1/2] Building CXX object CMakeFiles/constexpr-everything.dir/main.cpp.o
FAILED: CMakeFiles/constexpr-everything.dir/main.cpp.o 
/usr/lib64/ccache/c++  -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS  -std=c++14 -Wno-unused-parameter -Wall -Wextra -Wshadow -fno-strict-aliasing -fno-exceptions -fno-rtti   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -std=gnu++14 -MD -MT CMakeFiles/constexpr-everything.dir/main.cpp.o -MF CMakeFiles/constexpr-everything.dir/main.cpp.o.d -o CMakeFiles/constexpr-everything.dir/main.cpp.o -c ../main.cpp
../main.cpp: In member function ‘bool ConstexprFunctionASTVisitor::VisitFunctionDecl(clang::FunctionDecl*)’:
../main.cpp:233:11: error: ‘class clang::FunctionDecl’ has no member named ‘setConstexprKind’; did you mean ‘setConstexpr’?
  233 |     func->setConstexprKind(CSK_constexpr);
      |           ^~~~~~~~~~~~~~~~
      |           setConstexpr
../main.cpp:233:28: error: ‘CSK_constexpr’ was not declared in this scope; did you mean ‘constexpr’?
  233 |     func->setConstexprKind(CSK_constexpr);
      |                            ^~~~~~~~~~~~~
      |                            constexpr
../main.cpp: In member function ‘bool ConstexprVarDeclFunctionASTVisitor::ConstexprVarDeclVisitor::VisitDeclStmt(clang::DeclStmt*)’:
../main.cpp:279:13: warning: unused variable ‘sema’ [-Wunused-variable]
  279 |       auto &sema = CI_.getSema();
      |             ^~~~
../main.cpp: At global scope:
../main.cpp:40:6: warning: ‘bool {anonymous}::CheckConstexprDeclStmt(clang::Sema&, const clang::FunctionDecl*, clang::DeclStmt*, clang::SourceLocation&)’ defined but not used [-Wunused-function]
   40 | bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
      |      ^~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

I guess a newer LLVM version is required. Maybe a version check could be added to the CMakeLists.txt or at least the required LLVM version should be stated in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.