llvm / llvm/llvm-project

C standard allows standard library functions to compare equal

Open
#222,410 0 comments 0 reactions 0 assignees View on GitHub
new issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The resolution to https://www.open-std.org/jtc1/sc22/wg14/issues/c23/issue1003.html (which will be part of C2Y?) says that the following function may return true (https://godbolt.org/z/46WGe6G87):

```c
#include
int x() { return memcpy == memmove; }
```

areGlobalsPotentiallyEqual in llvm/lib/IR/ConstantFold.cpp assumes that pointers to different functions, not marked unnamed_addr, are not equal, so LLVM folds this to false.

We have the following options here, I think:

- Make areGlobalsPotentiallyEqual more conservative around function declarations.
- Make clang mark all function declarations unnamed_addr, or some similar marking. (We might need a different marking for declarations, specifically; I don't think this standard modification allows us to merge function definitions unless the user explicitly requests it.)
- Declare that any libc that actually does this sort of merge is incompatible with LLVM... but I think some C libraries actually do this merge.
- Go back to the C committee to ask for clarification.

Contributor guide

Open the contributing guide

Research direction

Start by reading areGlobalsPotentiallyEqual in llvm/lib/IR/ConstantFold.cpp, then review the linked C standard resolution and the Godbolt example. Determine how LLVM should represent or fold equality between distinct standard-library function declarations, and validate the chosen behavior with a focused regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.