Question regarding -Wlifetime

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question regarding -Wlifetime

Renato Golin via cfe-dev

Hi everyone,

just decided to start playing around with -Wlifetime on Godbolt, and came up with
an example that failed to meet my expectations, namely:

char *leak()
{
   return new char;
}

int main()
{
    char *ch = leak();
}

Shouldn't the lifetime static analyser complain that ch on main() leaks, or am I expecting too much from the analyser?

Initially I though that by using main(), the analyser just assumed it would be released anyway, but renaming it to something
else, still doesn't trigger a leak warning.

Thanks in advance,
Paulo

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding -Wlifetime

Renato Golin via cfe-dev
Hi Paulo,

The -Wlifetime analysis is not part of mainline clang yet (only the statement-local warnings). If you have some questions, concerns regarding the flow-sensitive analysis feel free to open a ticket at https://github.com/mgehre/llvm-project

Currently, the flow-sensitive lifetime analysis does not check for memory leaks. If you want to find leaks statically, you could try out the Clang Static Analyzer (https://clang-analyzer.llvm.org/) which has some great checks to find such issues.

Cheers,
Gabor

On Sat, 5 Oct 2019 at 11:10, Paulo Pinto via cfe-dev <[hidden email]> wrote:

Hi everyone,

just decided to start playing around with -Wlifetime on Godbolt, and came up with
an example that failed to meet my expectations, namely:

char *leak()
{
   return new char;
}

int main()
{
    char *ch = leak();
}

Shouldn't the lifetime static analyser complain that ch on main() leaks, or am I expecting too much from the analyser?

Initially I though that by using main(), the analyser just assumed it would be released anyway, but renaming it to something
else, still doesn't trigger a leak warning.

Thanks in advance,
Paulo
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding -Wlifetime

Renato Golin via cfe-dev

Hi Gabor,

thanks for the clarification.

I just got curious after the CppCon talk and wanted to check out the current state.

Cheers,
Paulo

Am 05.10.2019 um 11:22 schrieb Gábor Horváth:
Hi Paulo,

The -Wlifetime analysis is not part of mainline clang yet (only the statement-local warnings). If you have some questions, concerns regarding the flow-sensitive analysis feel free to open a ticket at https://github.com/mgehre/llvm-project

Currently, the flow-sensitive lifetime analysis does not check for memory leaks. If you want to find leaks statically, you could try out the Clang Static Analyzer (https://clang-analyzer.llvm.org/) which has some great checks to find such issues.

Cheers,
Gabor

On Sat, 5 Oct 2019 at 11:10, Paulo Pinto via cfe-dev <[hidden email]> wrote:

Hi everyone,

just decided to start playing around with -Wlifetime on Godbolt, and came up with
an example that failed to meet my expectations, namely:

char *leak()
{
   return new char;
}

int main()
{
    char *ch = leak();
}

Shouldn't the lifetime static analyser complain that ch on main() leaks, or am I expecting too much from the analyser?

Initially I though that by using main(), the analyser just assumed it would be released anyway, but renaming it to something
else, still doesn't trigger a leak warning.

Thanks in advance,
Paulo
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev