[Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers by dtcxzyw · Pull Request #130734 · llvm/llvm-project (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

dtcxzyw

@llvmbot llvmbot added clang

Clang issues not falling into any other category

clang:codegen

IR generation bugs: mangling, exceptions, etc.

labels

Mar 11, 2025

efriedma-quic

efriedma-quic

nikic

AaronBallman

efriedma-quic

dtcxzyw added a commit that referenced this pull request

Apr 3, 2025

@dtcxzyw

… type (#134221)

If CreateConstInBoundsGEP2_32 returns a constant null/gep, the cast to GetElementPtrInst will fail. This patch uses two static helpers GEPOperator::accumulateConstantOffset/GetElementPtrInst::getIndexedType to infer offset and result type instead of depending on the GEP result.

This patch is extracted from #130734.

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request

Apr 3, 2025

@dtcxzyw @github-actions

… and result type (#134221)

If CreateConstInBoundsGEP2_32 returns a constant null/gep, the cast to GetElementPtrInst will fail. This patch uses two static helpers GEPOperator::accumulateConstantOffset/GetElementPtrInst::getIndexedType to infer offset and result type instead of depending on the GEP result.

This patch is extracted from llvm/llvm-project#130734.

dtcxzyw added a commit that referenced this pull request

Apr 9, 2025

@dtcxzyw

…134269)

This patch turns off inbounds/nuw flags for member accesses when -fwrapv-pointer is set.

Closes #132449.

It is required by #130734.

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request

Apr 9, 2025

@dtcxzyw @github-actions

@dtcxzyw

@dtcxzyw

@dtcxzyw

AllinLeeYL pushed a commit to AllinLeeYL/llvm-project that referenced this pull request

Apr 10, 2025

@dtcxzyw

efriedma-quic

@dtcxzyw dtcxzyw deleted the offsetof-inbounds branch

April 11, 2025 01:04

dtcxzyw added a commit that referenced this pull request

Apr 11, 2025

@dtcxzyw

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request

Apr 11, 2025

@dtcxzyw @github-actions

var-const pushed a commit to ldionne/llvm-project that referenced this pull request

Apr 17, 2025

@dtcxzyw @var-const

var-const pushed a commit to ldionne/llvm-project that referenced this pull request

Apr 17, 2025

@dtcxzyw @var-const

…se pointers (llvm#130734)

In the LLVM middle-end we want to fold gep inbounds null, idx -> null: https://alive2.llvm.org/ce/z/5ZkPx- This pattern is common in real-world programs (dtcxzyw/llvm-opt-benchmark#55 (comment)). Generally, it exists in some (actually) unreachable blocks, which is introduced by JumpThreading.

However, some old-style offsetof macros are still widely used in real-world C/C++ code (e.g., hwloc/slurm/luajit). To avoid breaking existing code and inconvenience to downstream users, this patch removes the inbounds flag from the struct gep if the base pointer is null.

var-const pushed a commit to ldionne/llvm-project that referenced this pull request

Apr 17, 2025

@dtcxzyw @var-const

dtcxzyw added a commit that referenced this pull request

Apr 17, 2025

@dtcxzyw

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request

Apr 17, 2025

@dtcxzyw @github-actions

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request

May 6, 2025

@dtcxzyw @IanWood1

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request

May 6, 2025

@dtcxzyw @IanWood1