* . *
  • About
  • Advertise
  • Privacy & Policy
  • Contact
Sunday, July 6, 2025
Earth-News
  • Home
  • Business
  • Entertainment
    Magicians and Battlebots light up Las Vegas entertainment scene – KSNV

    Magicians and Battlebots Take Las Vegas Entertainment by Storm

    Max-Matching Entertainments & Longhua District form partnership for new entertainment complex – Blooloop

    Max-Matching Entertainments and Longhua District Unite to Launch Thrilling New Entertainment Complex

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    MAY HER SOUL REST IN PEACE 🙏 Veteran entertainment columnist and talent manager Lolit Solis has passed away. She was 78 years old. https://tinyurl.com/6kumarkx | LatestChika.com – Facebook

    Beloved Entertainment Icon Lolit Solis Passes Away at 78 – A Life Remembered with Love and Respect 🙏

    Neil Young Plays Rare Full-Band ‘Ambulance Blues’ With The Chrome Hearts – Yahoo

    Neil Young Stuns Fans with Rare Full-Band Performance of ‘Ambulance Blues’ Alongside The Chrome Hearts

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    EIFO invests $5 million in D3, the Ukraine-focused defence technology venture fund – sUAS News

    EIFO Pledges $5 Million to Supercharge Ukraine-Focused Defense Technology Fund

    New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

    Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

    Environmental cognitive distance, R&D capability distance, and supply chain green technology innovation – Nature

    Bridging Gaps: How Environmental and R&D Differences Drive Green Technology Innovation in Supply Chains

    LG Innotek CEO Moon Hyuksoo: “Our Next-gen Substrate Technology Will Change the Industry Paradigm” – TechPowerUp

    LG Innotek CEO Moon Hyuksoo: “Our Next-Gen Substrate Technology Will Revolutionize the Industry” Revolutionizing the Future: LG Innotek’s CEO Unveils Game-Changing Next-Gen Substrate Technology

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
  • Home
  • Business
  • Entertainment
    Magicians and Battlebots light up Las Vegas entertainment scene – KSNV

    Magicians and Battlebots Take Las Vegas Entertainment by Storm

    Max-Matching Entertainments & Longhua District form partnership for new entertainment complex – Blooloop

    Max-Matching Entertainments and Longhua District Unite to Launch Thrilling New Entertainment Complex

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    MAY HER SOUL REST IN PEACE 🙏 Veteran entertainment columnist and talent manager Lolit Solis has passed away. She was 78 years old. https://tinyurl.com/6kumarkx | LatestChika.com – Facebook

    Beloved Entertainment Icon Lolit Solis Passes Away at 78 – A Life Remembered with Love and Respect 🙏

    Neil Young Plays Rare Full-Band ‘Ambulance Blues’ With The Chrome Hearts – Yahoo

    Neil Young Stuns Fans with Rare Full-Band Performance of ‘Ambulance Blues’ Alongside The Chrome Hearts

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    EIFO invests $5 million in D3, the Ukraine-focused defence technology venture fund – sUAS News

    EIFO Pledges $5 Million to Supercharge Ukraine-Focused Defense Technology Fund

    New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

    Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

    Environmental cognitive distance, R&D capability distance, and supply chain green technology innovation – Nature

    Bridging Gaps: How Environmental and R&D Differences Drive Green Technology Innovation in Supply Chains

    LG Innotek CEO Moon Hyuksoo: “Our Next-gen Substrate Technology Will Change the Industry Paradigm” – TechPowerUp

    LG Innotek CEO Moon Hyuksoo: “Our Next-Gen Substrate Technology Will Revolutionize the Industry” Revolutionizing the Future: LG Innotek’s CEO Unveils Game-Changing Next-Gen Substrate Technology

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
Earth-News
No Result
View All Result
Home Technology

C++ Insights – See your source code with the eyes of a compiler

April 6, 2024
in Technology
C++ Insights – See your source code with the eyes of a compiler
Share on FacebookShare on Twitter

cpp insights logo

License download Build Status
codecov
Try online
Documentation
patreon

Open in Gitpod

What
Why
Building
Usage
Get Involved
Support

C++ Insights is a Clang-based tool that does a source-to-source
transformation. The goal of C++ Insights is to make things visible that normally and intentionally happen behind the scenes.
It’s about the magic the compiler does for us to make things work.

Take this piece of code for example:

class Base {
};

class Derived : public Base {
};

int main() {
Derived d;

Derived d2=d;

d2=d;

Base& b=d;
}

Nothing special, and of course, it compiles. This is the compiler’s view on it:

class Base
{
public:
// inline constexpr Base() noexcept=default;
// inline constexpr Base(const Base &) noexcept=default;
// inline constexpr Base & operator=(const Base &) noexcept=default;
};

class Derived : public Base
{
public:
// inline constexpr Derived() noexcept=default;
// inline constexpr Derived(const Derived &) noexcept=default;
// inline constexpr Derived & operator=(const Derived &) noexcept=default;
};

int main()
{
Derived d;
Derived d2=Derived(d);
d2.operator=(d);
Base & b=static_cast(d);
return 0;
}

You can see all the compiler-provided special member functions and the downcast from Derived to Base.

C++ Insights is a Clang-based tool that does a source-to-source transformation.
The goal of C++ Insights is to make things visible that normally and intentionally happen behind the scenes. It’s about the magic the compiler does
for us to make things work. Or looking through the classes of a compiler.

In 2017, I started looking into some new things we got with C++11, C++14, and C++17. Amazing things like lambdas, range-based for-loops,
and structured bindings. I put it together in a talk. You can find the slides
and a video online.

However, all that research and some of my training and teaching got me to start thinking about how it would be if we could see with the eyes
of the compiler. Sure, there is an AST dump, at least for Clang. We can see what code the compiler generates from a C++ source snippet with
tools like Compiler Explorer. However, what we see is assembler. Neither the AST nor the Compiler Explorer output is in the language I write
code. Hence, I’m not very familiar with this output. Plus, when teaching students C++, showing an AST and explaining that it is all there was
not quite satisfying for me.

I started to write a Clang-based tool that can transform a range-based for-loop into the compiler-internal version. Then, I did the same
for structured bindings and lambdas. In the end, I did much more than initially planned. It shows where operators are
invoked and places in which the compiler does some casting. C++ Insights can deduce the type behind auto or decltype. The goal
is to produce compilable code. However, this is not possible in all places.

You can see, for example, the transformation of a lambda, range-based for-loop, or auto. Of course, you can transform any other C++ snippet.

See yourself. C++ Insights is available online: cppinsights.io.

Still, there is work to do.

I do not claim to get all the things right. I’m also working on supporting features from new standards, like C++20, at the moment.
Please remember that C++ Insights is based on Clang and its understanding of the AST.

I did a couple of talks about C++ Insights since I released C++ Insights. For example, at C++ now. Here are the slides and the video.

C++ Insights can be built inside the Clang source tree or outside.

See Readme_Windows.md

To build with extra/clang use the following extra flags: -DINSIGHTS_USE_SYSTEM_INCLUDES=off -DCLANG_LINK_CLANG_DYLIB=on -DLLVM_LINK_LLVM_DYLIB=on

See #186 for an explanation of why INSIGHTS_USE_SYSTEM_INCLUDES needs to be turned off.

extra/clang and extra/llvm provide /usr/lib/{libclangAST.so,libLLVM*.a,libLLVM.so}. libclangAST.so needs libLLVM.so and there would be a conflict if libLLVM*.a (instead of libLLVM.so) are linked. See https://bugs.archlinux.org/task/60512

You need to have a Clang installation in the search path.

git clone https://github.com/andreasfertig/cppinsights.git
mkdir build && cd build
cmake -G”Ninja” ../cppinsights
ninja

The resulting binary (insights) can be found in the build folder.

For building it inside the Clang source tree, assuming you have your source tree already prepared under llvm-project:

cd llvm-project/clang-tools-extra/
git clone https://github.com/andreasfertig/cppinsights.git

echo “add_subdirectory(cppinsights)”>> CMakeLists.txt

To activate the C++ Insights build you have to set -DLLVM_ENABLE_PROJECTS=”clang;clang-tools-extra” for cmake:

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=”clang;clang-tools-extra” -G “Unix Makefiles” ../llvm-project

Then, build Clang as you normally do.

There are a couple of options that can be enabled with cmake:

Option
Description
Default

INSIGHTS_STRIP
Strip insight after build
ON

INSIGHTS_STATIC
Use static linking
OFF

INSIGHTS_COVERAGE
Enable code coverage
OFF

INSIGHTS_USE_LIBCPP
Use libc++ for tests
OFF

DEBUG
Enable debug
OFF

Building for ARM on macOS

It seems best to supply the architecture during configuration:

cmake -DCMAKE_OSX_ARCHITECTURES=arm64 ../cppinsights

git clone https://github.com/andreasfertig/cppinsights.git
mkdir build_eclipse
cd build_eclipse
cmake -G”Eclipse CDT4 – Unix Makefiles” ../cppinsights/

Then, in Cevelop Import -> General -> Existing Project into Workspace. Select build_eclipse. Enjoy editing with
Cevelop.

Using C++ Insights is fairly simple:

insights — -std=c++17

Things get complicated when it comes to the system-include paths. These paths are hard-coded in the binary, which seems
to come from the compiler C++ Insights was built with. To help with that, check out scripts/getinclude.py. The script tries to
collect the system-include paths from the compiler. Without an option, getinclude.py uses g++. You can also pass another compiler
as a first argument.

Here is an example:

./scripts/getinclude.py
-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -isystem/usr/local/include -isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/include -isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -isystem/usr/include

The script can be used together with C++ Insights:

insights — -std=c++17 `./scripts/getinclude.py`

In case you have a custom build of the GCC compiler, for example, gcc-11.2.0, and NOT installed in the compiler in the default system path, then after building, Clang fails to find the correct libstdc++ path (GCC’s STL). If you run into this situation, you can use “–gcc-toolchain=/path/GCC-1x.x.x/installed/path” to tell Clang/C++ Insights the location of the STL:

./cppinsights Insights.cpp — –gcc-toolchain=${GCC_11_2_0_INSTALL_PATH} -std=c++20

Here “${GCC_11_2_0_INSTALL_PATH}” is the installation directory of your customized-built GCC. The option for Clang is described here.

Ready to use Docker container

There is also another GitHub project that sets up a docker container with the latest C++ Insights version in it: C++
Insights – Docker

A plugin for Vim is available at
here.

An extension for Visual Studio Code is available at the VS Code marketplace: C++
Insights – VSCode Extension.

At least for macOS, you can install C++ Insights via Homebrew thanks to this formulae:

I aim for the repository to compile with the latest version of Clang and at least the one before. The website tries to
stay close to the latest release of Clang. However, due to certain issues (building Clang for Windows), the website’s
version is often delayed by a few months.

I created a YouTube channel where I release a new video each month. In
these videos, I use C++ Insights to show and explain certain C++ constructs, and sometimes I explain C++ Insights as well.

See TODO.

Report bugs/issues by submitting a GitHub issue.
Submit contributions using pull requests. See Contributing

If you like to support the project, consider submitting a patch. Another alternative is to become a GitHub Sponsor or a Patreon supporter.

>>> Read full article>>>
Copyright for syndicated content belongs to the linked Source : Hacker News – https://github.com/andreasfertig/cppinsights

Tags: Insightssourcetechnology
Previous Post

SearXNG is a free internet metasearch engine

Next Post

Why CockroachDB doesn’t use EvalPlanQual

New book digs into Indigenous cuisine through archaeology, culture, ecology – Gander Newsroom

Unveiling Indigenous Cuisine: Exploring the Rich Tapestry of Archaeology, Culture, and Ecology

July 6, 2025
BANG! James Webb telescope catches stray galaxies in the Bullet Cluster: Space photo of the week – Live Science

BANG! James Webb Telescope Unveils Breathtaking Image of Stray Galaxies in the Bullet Cluster

July 6, 2025
How Do You Teach Computer Science in the A.I. Era? – The New York Times

Unlocking Success: Mastering Computer Science Education in the Age of A.I

July 6, 2025
If you want to be younger looking in 60 days, start practicing these 8 daily habits – VegOut

If you want to be younger looking in 60 days, start practicing these 8 daily habits – VegOut

July 6, 2025
Real Madrid vs Borussia Dortmund 3-2: FIFA Club World Cup – as it happened – Al Jazeera

Real Madrid vs Borussia Dortmund 3-2: FIFA Club World Cup – as it happened – Al Jazeera

July 6, 2025

Israel’s economy can’t survive a long war with Iran – and Trump knows it – Middle East Eye

July 6, 2025
The long-term health risks as extreme heat becomes a new normal – PBS

Uncovering the Silent, Long-Term Health Risks of Life in Extreme Heat

July 6, 2025
Trump Says He Will Start Talks With China on TikTok Deal – The New York Times

Trump Says He Will Start Talks With China on TikTok Deal – The New York Times

July 6, 2025
EIFO invests $5 million in D3, the Ukraine-focused defence technology venture fund – sUAS News

EIFO Pledges $5 Million to Supercharge Ukraine-Focused Defense Technology Fund

July 6, 2025
Winning sports’ woke war is great, but unfortunately it’s led by the absurd – New York Post

The Thrilling Battle for Sports Culture Is Fueled by the Absurd

July 6, 2025

Categories

Archives

July 2025
MTWTFSS
 123456
78910111213
14151617181920
21222324252627
28293031 
« Jun    
Earth-News.info

The Earth News is an independent English-language daily published Website from all around the World News

Browse by Category

  • Business (20,132)
  • Ecology (707)
  • Economy (732)
  • Entertainment (21,621)
  • General (15,739)
  • Health (9,770)
  • Lifestyle (737)
  • News (22,149)
  • People (733)
  • Politics (741)
  • Science (15,949)
  • Sports (21,231)
  • Technology (15,716)
  • World (713)

Recent News

New book digs into Indigenous cuisine through archaeology, culture, ecology – Gander Newsroom

Unveiling Indigenous Cuisine: Exploring the Rich Tapestry of Archaeology, Culture, and Ecology

July 6, 2025
BANG! James Webb telescope catches stray galaxies in the Bullet Cluster: Space photo of the week – Live Science

BANG! James Webb Telescope Unveils Breathtaking Image of Stray Galaxies in the Bullet Cluster

July 6, 2025
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

Go to mobile version