Skip to content

Do not unnecessarily mark local variables static #2471

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

Merged
merged 1 commit into from
Jul 3, 2018

Conversation

tautschnig
Copy link
Collaborator

No description provided.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 7191f23).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/77256446
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for the strings I'd guess the compiler will construct it once per function call vs. only on first call? It seems like this could only make things worse than static const

@tautschnig
Copy link
Collaborator Author

It seems like this could only make things worse than static const

I'm not sure I agree: static locals introduce a branch (to test whether initialization is necessary) on each invocation and, at least for GCC (and possibly also VS, if C++11 is fully implemented), setting up a mutex to avoid deadlocks.

For sure I'm not going to insist on getting this PR in in its current form, but this rather random sprinkling of static is an attempt at optimisation that I doubt is backed by data?!

@tautschnig
Copy link
Collaborator Author

In line with my above comment: the assembler output of compiling

#include <string>

int main(int argc, char *argv[])
{
  static const std::string bla = "bla";
  return bla == argv[0];
}

vs. the same while removing static confirms my above statement. But of course that in itself isn't sufficient to show any performance gain or loss.

I'd say: if you seriously want a constant of static lifetime for performance reasons, you might as well declare a file-local global constant.

@smowton
Copy link
Contributor

smowton commented Jun 26, 2018

The one reason I rarely do that is for static const irep_idt, which must be init'd after the string table -- on first use of a particular function is a convenient way to achieve that, without risking the same string-to-irep_idt conversion happening frequently.

Still as you say, it's not like I have any data one way or the other, so not blocking this.

@kroening
Copy link
Member

kroening commented Jul 3, 2018

The non-static variant tends to be more optimisation-friendly, I believe (no hard data either).
Let's go for it.

@kroening kroening merged commit 72b92a4 into diffblue:develop Jul 3, 2018
@tautschnig tautschnig deleted the vs-non-static branch July 3, 2018 11:12
NathanJPhillips added a commit to NathanJPhillips/cbmc that referenced this pull request Aug 22, 2018
f90ed9e Merge pull request diffblue#2515 from NathanJPhillips/feature/ignored-methods
4a12a29 Prevent crash when only instance of class is marked as an overlay
841313d Add ability to mark methods as ignored (not loaded)
0c20014 Merge pull request diffblue#2513 from tautschnig/clean
4c14354 Merge pull request diffblue#2490 from tautschnig/switch-range
72b92a4 Merge pull request diffblue#2471 from tautschnig/vs-non-static
1941c6c Merge pull request diffblue#2508 from tautschnig/skip-typecast
a9e4ce9 Merge pull request diffblue#2512 from tautschnig/fix-typo
2be11f3 Make "clean" target in regression tests do full cleanup
97e9314 Do not hardcode tests.log as option -s <suffix> may be in use
ad1f266 Fix typo seperated -> separated
15d4307 Evaluate expressions that delimit GCC switch/case ranges
770b779 Make skip_typecast widely available
b4f5800 Merge pull request diffblue#2492 from NathanJPhillips/doc/get_writeable_symbol
b58813b Merge pull request diffblue#2479 from thk123/bugfix/TG-3908/give-string-objects-names
fd2f21e Use new method to set the name
190b485 Introduce method for getting the name of of java_class_type
ffbb83f Merge pull request diffblue#2496 from diffblue/compilation-instructions2
594c2f2 unzip is needed on Debian, plus say how to build jbmc on Windows
dabc169 Given string types an appropriate name
76eaf86 Doxygen comment on get_writeable_symbol
7191f23 Do not unnecessarily mark local variables static

git-subtree-dir: cbmc
git-subtree-split: f90ed9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants