Skip to content

[SYCL] Fix -Wmain error in dpllvm.cpp#22623

Merged
uditagarwal97 merged 3 commits into
intel:syclfrom
wenju-he:fix-Wmain
Jul 16, 2026
Merged

[SYCL] Fix -Wmain error in dpllvm.cpp#22623
uditagarwal97 merged 3 commits into
intel:syclfrom
wenju-he:fix-Wmain

Conversation

@wenju-he

@wenju-he wenju-he commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

reinterpret_cast<void *>(main) is a Clang extension warning (-Wmain) that becomes an error under -Werror. Use the same idom in llvm/tools/llvm-config/llvm-config.cpp.

Fixes a regression from 328217f.

reinterpret_cast<void *>(main) is a Clang extension warning
(-Wmain) that becomes an error under -Werror. Use the address of a
local anchor function instead, matching the idiom already used in
clang/tools/driver/driver.cpp and llvm/tools/llvm-config/llvm-config.cpp.

Fixes a regression from 328217f.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@wenju-he
wenju-he requested a review from a team as a code owner July 14, 2026 02:19

@Fznamznon Fznamznon left a comment

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 don't we do it the same way as llvm tools, instead of adding an empty function, do

/// Compute the path to the main executable.
static std::string getExecutablePath(const char *Argv0) {
  // This just needs to be some symbol in the binary; C++ doesn't
  // allow taking the address of ::main however.
  void *P = (void *)(intptr_t)getExecutablePath;
  return sys::fs::getMainExecutable(Argv0, P);
}

@wenju-he

Copy link
Copy Markdown
Contributor Author

Why don't we do it the same way as llvm tools, instead of adding an empty function, do

/// Compute the path to the main executable.
static std::string getExecutablePath(const char *Argv0) {
  // This just needs to be some symbol in the binary; C++ doesn't
  // allow taking the address of ::main however.
  void *P = (void *)(intptr_t)getExecutablePath;
  return sys::fs::getMainExecutable(Argv0, P);
}

this file only has one function: main

@wenju-he
wenju-he requested a review from Fznamznon July 15, 2026 04:29
@wenju-he

Copy link
Copy Markdown
Contributor Author

/// Compute the path to the main executable.
static std::string getExecutablePath(const char *Argv0) {
// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
void *P = (void *)(intptr_t)getExecutablePath;
return sys::fs::getMainExecutable(Argv0, P);
}

done, thanks

@wenju-he

Copy link
Copy Markdown
Contributor Author

@intel/llvm-gatekeepers please merge, thanks.
BMG fail Test d:\github\_work\llvm\llvm\build-e2e\specconstants\2020\non_native\output\gpu.cpp.tmp.out hung! is reported to #22405

@uditagarwal97
uditagarwal97 merged commit f98590d into intel:sycl Jul 16, 2026
30 of 31 checks passed
@wenju-he
wenju-he deleted the fix-Wmain branch July 17, 2026 00:51
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.

4 participants