llvm / llvm/llvm-project

`-Wuninitialized-const-pointer` fires on valid MemorySanitizer usage

Open
#160,094 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clang:diagnostics compiler-rt:msan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The recently introduced -Wuninitialized-const-pointer warning is triggered by a legitimate usage of the MemorySanitizer __msan_allocated_memory call:

#include <sanitizer/msan_interface.h>
int main(void) {
  int a;
  __msan_allocated_memory(&a, sizeof(a));
  return 0;
}

Command and output:

$ clang-21 test.c -o test -fsanitize=memory -Wall
test.c:4:28: warning: variable 'a' is uninitialized when passed as a const pointer argument here [-Wuninitialized-const-pointer]
    4 |   __msan_allocated_memory(&a, sizeof(a));
      |                            ^
1 warning generated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the C example, the sanitizer/msan_interface.h declaration, and the shown clang-21 command using -fsanitize=memory -Wall. Trace how -Wuninitialized-const-pointer handles the __msan_allocated_memory call; done means this valid MemorySanitizer usage no longer emits the warning while the warning still diagnoses genuine cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.