Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid nullptr diagnostic #47878

Closed
tlemo opened this issue Dec 16, 2020 · 4 comments
Closed

Invalid nullptr diagnostic #47878

tlemo opened this issue Dec 16, 2020 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:static analyzer confirmed Verified by a second party

Comments

@tlemo
Copy link
Collaborator

tlemo commented Dec 16, 2020

Bugzilla Link 48534
Version unspecified
OS All
CC @devincoughlin,@haoNoQ

Extended Description

// https://godbolt.org/z/1oze6v

struct IrBuilder;
struct Kernel;

class Passkey {
friend struct IrBuilder;
explicit Passkey(Kernel* kernel) : kernel(kernel) {}

public:
Kernel* const kernel = nullptr;
};

struct Kernel {
void foo() const;
};

struct Node {
// incorrect note: Called C++ object pointer is null
explicit Node(Passkey passkey) { passkey.kernel->foo(); }
};

// enabling the following piece of code (normally in a different translation unit)
// demonstrates that the diagnostic is incorrect
#if 0
struct IrBuilder {
Node* create() {
const Passkey passkey(kernel_);
return new Node(passkey);
}

Kernel* kernel_ = nullptr;

};

Node* test(IrBuilder* ir_builder) {
return ir_builder->create();
}
#endif

:19:38: warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage] explicit Node(Passkey passkey) { passkey.kernel->foo(); } ^ :19:38: note: Called C++ object pointer is null 1 warning generated.
@tlemo
Copy link
Collaborator Author

tlemo commented Dec 16, 2020

assigned to @haoNoQ

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 17, 2020

Moving to Static-analyzer bugs

@haoNoQ
Copy link
Collaborator

haoNoQ commented Dec 17, 2020

Aha, uhm, yeah, i see. The static analyzer indeed thinks that a combination of "const" and a field initializer causes the field to forever stay that way. We'll need to undo this relatively recently added shortcut.

@haoNoQ
Copy link
Collaborator

haoNoQ commented Jul 22, 2021

(probably caused by code in RegionStoreManager::getBindingForField())

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:static analyzer confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants