Skip to content

[WIP][IR][Constants] Change the semantic of ConstantPointerNull to represent an actual nullptr instead of a zero-value pointer - #183215

Draft
shiltian wants to merge 1 commit into
users/shiltian/getnullvalue-callers-datalayoutfrom
users/shiltian/constant-pointer-null-semantic
Draft

[WIP][IR][Constants] Change the semantic of ConstantPointerNull to represent an actual nullptr instead of a zero-value pointer#183215
shiltian wants to merge 1 commit into
users/shiltian/getnullvalue-callers-datalayoutfrom
users/shiltian/constant-pointer-null-semantic

Conversation

@shiltian

@shiltian shiltian commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

This WIP PR stack basically shows how the changes would pan out. It will be easier to review the changes than #166667.

  • It is assumed that no specification of null pointer value in data layout means its value is zero. This is to align with LLVM's existing behavior.
  • Without the DataLayout * in those functions, the constant folding will have to be conservative.
  • There are still many Constant::get that need to be updated to pass DataLayout * into the function call. That might be the most intrusive changes in this PR stack. I'd greatly appreciate any idea that can make the changes smaller or less intrusive.

@shiltian shiltian changed the title WIP [WIP][IR][Constants] Change the semantic of ConstantPointerNull to represent an actual nullptr instead of a zero-value pointer Feb 24, 2026
@github-actions

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 3119 tests passed
  • 7 tests skipped

All executed tests passed, but another part of the build failed. Click on a failure below to see the details.

lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.o
FAILED: lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.o
sccache /opt/llvm/bin/clang++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/Target/Hexagon -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fvisibility=hidden -UNDEBUG -fno-exceptions -funwind-tables -fno-rtti -MD -MT lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.o -MF lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.o.d -o lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:1415:50: error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
1415 |     Value *Zero = Constant::getNullValue(SecTy, &DL);
|                                                  ^~
|                                                  HexagonVectorCombine::DL
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:177:21: note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:1415:50: error: invalid use of non-static data member 'DL'
1415 |     Value *Zero = Constant::getNullValue(SecTy, &DL);
|                                                  ^~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:2987:64: error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
2987 |     Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                                ^~
|                                                                HexagonVectorCombine::DL
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:177:21: note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:2987:64: error: invalid use of non-static data member 'DL'
2987 |     Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                                ^~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:3067:77: error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
3067 |         CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)), &DL);
|                                                                             ^~
|                                                                             HexagonVectorCombine::DL
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:177:21: note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:3067:77: error: invalid use of non-static data member 'DL'
3067 |         CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)), &DL);
|                                                                             ^~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:3215:62: error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
3215 |   Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                              ^~
|                                                              HexagonVectorCombine::DL
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:177:21: note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp:3215:62: error: invalid use of non-static data member 'DL'
3215 |   Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                              ^~
8 errors generated.
lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.o
FAILED: lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.o
sccache /opt/llvm/bin/clang++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/Target/SPIRV -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fvisibility=hidden -UNDEBUG -fno-exceptions -funwind-tables -fno-rtti -MD -MT lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.o -MF lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.o.d -o lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:147:44: error: out-of-line definition of 'legalizeConstant' does not match any declaration in '(anonymous namespace)::SPIRVLegalizeZeroSizeArraysImpl'
147 | Constant *SPIRVLegalizeZeroSizeArraysImpl::legalizeConstant(Constant *C) {
|                                            ^~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:59:7: note: SPIRVLegalizeZeroSizeArraysImpl defined here
59 | class SPIRVLegalizeZeroSizeArraysImpl
|       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:165:57: error: too few arguments to function call, expected 2, have 1
165 |       Elems.push_back(legalizeConstant(cast<Constant>(U)));
|                       ~~~~~~~~~~~~~~~~                  ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:78:13: note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:172:58: error: too few arguments to function call, expected 2, have 1
172 |       Fields.push_back(legalizeConstant(cast<Constant>(U)));
|                        ~~~~~~~~~~~~~~~~                  ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:78:13: note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:184:65: error: too few arguments to function call, expected 2, have 1
184 |       Constant *LegalizedOp = legalizeConstant(cast<Constant>(U));
|                               ~~~~~~~~~~~~~~~~                  ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:78:13: note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:300:74: error: too few arguments to function call, expected 2, have 1
300 |     Constant *LegalizedInitializer = legalizeConstant(GV.getInitializer());
|                                      ~~~~~~~~~~~~~~~~                    ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizeZeroSizeArrays.cpp:78:13: note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 errors generated.
lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.o
FAILED: lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.o
sccache /opt/llvm/bin/clang++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/Target/WebAssembly -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/WebAssembly -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fvisibility=hidden -UNDEBUG -fno-exceptions -funwind-tables -fno-rtti -MD -MT lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.o -MF lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.o.d -o lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp:119:61: error: member access into incomplete type 'Module'
119 |                                &MF.getFunction().getParent()->getDataLayout()));
|                                                             ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/IR/Analysis.h:21:7: note: forward declaration of 'llvm::Module'
21 | class Module;
|       ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp:125:61: error: member access into incomplete type 'Module'
125 |                                &MF.getFunction().getParent()->getDataLayout()));
|                                                             ^
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/IR/Analysis.h:21:7: note: forward declaration of 'llvm::Module'
21 | class Module;
|       ^
2 errors generated.

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@github-actions

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 3058 tests passed
  • 29 tests skipped

All executed tests passed, but another part of the build failed. Click on a failure below to see the details.

[code=1] lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.obj
FAILED: [code=1] lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.obj
sccache C:\clang\clang-msvc\bin\clang-cl.exe  /nologo -TP -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib\Target\Hexagon -IC:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon -Iinclude -IC:\_work\llvm-project\llvm-project\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj /permissive- -Werror=unguarded-availability-new /W4  -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 /Ob2  -MD -UNDEBUG /EHs-c- /GR- -std:c++17 /showIncludes /Folib\Target\Hexagon\CMakeFiles\LLVMHexagonCodeGen.dir\HexagonVectorCombine.cpp.obj /Fdlib\Target\Hexagon\CMakeFiles\LLVMHexagonCodeGen.dir\LLVMHexagonCodeGen.pdb -c -- C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(1415,50): error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
1415 |     Value *Zero = Constant::getNullValue(SecTy, &DL);
|                                                  ^~
|                                                  HexagonVectorCombine::DL
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(177,21): note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(1415,50): error: invalid use of non-static data member 'DL'
1415 |     Value *Zero = Constant::getNullValue(SecTy, &DL);
|                                                  ^~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(2987,64): error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
2987 |     Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                                ^~
|                                                                HexagonVectorCombine::DL
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(177,21): note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(2987,64): error: invalid use of non-static data member 'DL'
2987 |     Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                                ^~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(3067,77): error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
3067 |         CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)), &DL);
|                                                                             ^~
|                                                                             HexagonVectorCombine::DL
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(177,21): note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(3067,77): error: invalid use of non-static data member 'DL'
3067 |         CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)), &DL);
|                                                                             ^~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(3215,62): error: use of undeclared identifier 'DL'; did you mean 'HexagonVectorCombine::DL'?
3215 |   Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                              ^~
|                                                              HexagonVectorCombine::DL
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(177,21): note: 'HexagonVectorCombine::DL' declared here
177 |   const DataLayout &DL;
|                     ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\Hexagon\HexagonVectorCombine.cpp(3215,62): error: invalid use of non-static data member 'DL'
3215 |   Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
|                                                              ^~
8 errors generated.
[code=1] lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.obj
FAILED: [code=1] lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.obj
sccache C:\clang\clang-msvc\bin\clang-cl.exe  /nologo -TP -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib\Target\SPIRV -IC:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV -Iinclude -IC:\_work\llvm-project\llvm-project\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj /permissive- -Werror=unguarded-availability-new /W4  -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 /Ob2  -MD -UNDEBUG /EHs-c- /GR- -std:c++17 /showIncludes /Folib\Target\SPIRV\CMakeFiles\LLVMSPIRVCodeGen.dir\SPIRVLegalizeZeroSizeArrays.cpp.obj /Fdlib\Target\SPIRV\CMakeFiles\LLVMSPIRVCodeGen.dir\LLVMSPIRVCodeGen.pdb -c -- C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(147,44): error: out-of-line definition of 'legalizeConstant' does not match any declaration in '(anonymous namespace)::SPIRVLegalizeZeroSizeArraysImpl'
147 | Constant *SPIRVLegalizeZeroSizeArraysImpl::legalizeConstant(Constant *C) {
|                                            ^~~~~~~~~~~~~~~~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(59,7): note: SPIRVLegalizeZeroSizeArraysImpl defined here
59 | class SPIRVLegalizeZeroSizeArraysImpl
|       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(165,57): error: too few arguments to function call, expected 2, have 1
165 |       Elems.push_back(legalizeConstant(cast<Constant>(U)));
|                       ~~~~~~~~~~~~~~~~                  ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(78,13): note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(172,58): error: too few arguments to function call, expected 2, have 1
172 |       Fields.push_back(legalizeConstant(cast<Constant>(U)));
|                        ~~~~~~~~~~~~~~~~                  ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(78,13): note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(184,65): error: too few arguments to function call, expected 2, have 1
184 |       Constant *LegalizedOp = legalizeConstant(cast<Constant>(U));
|                               ~~~~~~~~~~~~~~~~                  ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(78,13): note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(300,74): error: too few arguments to function call, expected 2, have 1
300 |     Constant *LegalizedInitializer = legalizeConstant(GV.getInitializer());
|                                      ~~~~~~~~~~~~~~~~                    ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\SPIRV\SPIRVLegalizeZeroSizeArrays.cpp(78,13): note: 'legalizeConstant' declared here
78 |   Constant *legalizeConstant(Constant *C, const DataLayout *DL);
|             ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 errors generated.
[code=1] lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.obj
FAILED: [code=1] lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.obj
sccache C:\clang\clang-msvc\bin\clang-cl.exe  /nologo -TP -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib\Target\WebAssembly -IC:\_work\llvm-project\llvm-project\llvm\lib\Target\WebAssembly -Iinclude -IC:\_work\llvm-project\llvm-project\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj /permissive- -Werror=unguarded-availability-new /W4  -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported /Gw /O2 /Ob2  -MD -UNDEBUG /EHs-c- /GR- -std:c++17 /showIncludes /Folib\Target\WebAssembly\CMakeFiles\LLVMWebAssemblyCodeGen.dir\WebAssemblyRegStackify.cpp.obj /Fdlib\Target\WebAssembly\CMakeFiles\LLVMWebAssemblyCodeGen.dir\LLVMWebAssemblyCodeGen.pdb -c -- C:\_work\llvm-project\llvm-project\llvm\lib\Target\WebAssembly\WebAssemblyRegStackify.cpp
C:\_work\llvm-project\llvm-project\llvm\lib\Target\WebAssembly\WebAssemblyRegStackify.cpp(119,61): error: member access into incomplete type 'Module'
119 |                                &MF.getFunction().getParent()->getDataLayout()));
|                                                             ^
C:\_work\llvm-project\llvm-project\llvm\include\llvm/IR/Analysis.h(21,7): note: forward declaration of 'llvm::Module'
21 | class Module;
|       ^
C:\_work\llvm-project\llvm-project\llvm\lib\Target\WebAssembly\WebAssemblyRegStackify.cpp(125,61): error: member access into incomplete type 'Module'
125 |                                &MF.getFunction().getParent()->getDataLayout()));
|                                                             ^
C:\_work\llvm-project\llvm-project\llvm\include\llvm/IR/Analysis.h(21,7): note: forward declaration of 'llvm::Module'
21 | class Module;
|       ^
2 errors generated.

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@QuantumSegfault

Copy link
Copy Markdown
Contributor

I wonder, would this (perhaps with additional work?) eventually allow Wasm's ref.null for externref and funcref to be lowered from this new nullptr, rather than requiring an intrinsic call.

Wasm uses non-integral address spaces to represent externref and funcref. But this PR just seems to impact the integer null value of integral pointers?

@shiltian

Copy link
Copy Markdown
Contributor Author

I wonder, would this (perhaps with additional work?) eventually allow Wasm's ref.null for externref and funcref to be lowered from this new nullptr, rather than requiring an intrinsic call.

Wasm uses non-integral address spaces to represent externref and funcref. But this PR just seems to impact the integer null value of integral pointers?

I'm not familiar with WASM, but the ideal here is, the ConstantPointerNull will represent a real nullptr, and its value can only be 0 or ~0U. The previous attempt did allow an arbitrary value, but eventually is not included because LLVM doesn't have the infrastructure to support that anyway. Given that, it doesn't seem to be able to represent a nullptr in WASM.

if (isa<ConstantPointerNull>(C)) {
const APInt &NullVal = DL.getNullPtrValue(AS);
return ConstantInt::get(
DestTy, NullVal.zextOrTrunc(DestTy->getIntegerBitWidth()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why zext or trunc? I'd expect a -1 pointer to be sign extended to -1

if (isa<ConstantPointerNull>(V)) {
const APInt &NullVal = DL->getNullPtrValue(AS);
return ConstantInt::get(
DestTy, NullVal.zextOrTrunc(DestTy->getIntegerBitWidth()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, why is this zext?

Comment thread llvm/lib/IR/Constants.cpp
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
case Type::PointerTyID: {
auto *Zero = ConstantInt::get(Type::getInt8Ty(Ty->getContext()), 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConstantInt::getZero

@shiltian

Copy link
Copy Markdown
Contributor Author

I also want to get feedback on options to represent a real zero-value pointer. This PR stack chose to use inttoptr 0, and then changed the printer and parser to recognize it. Is this really the best option? I wonder if there is any alternatives, like introducing a new class or something.

@nikic @arsenm @arichardson

@arsenm

arsenm commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

inttoptr 0 seems fine to me. If 0 isn't the null value, 0 isn't special relative to any other integer value

@github-actions
github-actions Bot deleted the users/shiltian/constant-pointer-null-semantic branch April 28, 2026 09:07
@github-actions
github-actions Bot deleted the branch users/shiltian/getnullvalue-callers-datalayout April 28, 2026 09:09
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

Successfully merging this pull request may close these issues.

3 participants