# GDC compiler settings on codechef

**URL:** <https://discuss.codechef.com/t/gdc-compiler-settings-on-codechef/95359>\
**Category:** general\
**Tags:** compiler, dlang\
**Created:** [October 12, 2021, 8:55pm UTC](https://discuss.codechef.com/t/gdc-compiler-settings-on-codechef/95359 "2021-10-12T20:55:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ssvb](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssvb/32/216702_2.png) [@ssvb](https://discuss.codechef.com/u/ssvb)\
**Post date:** [October 17, 2021, 7:58am UTC](https://discuss.codechef.com/t/gdc-compiler-settings-on-codechef/95359/3 "2021-10-17T07:58:37Z")

</div>

Thanks! How long does it usually take until the next iteration of language updates? The comment about the status of programming languages and compilers was last updated in 2017. I can see that in 2019 there was a report about Rust compiler not enabling optimizations, but nobody replied in the forum. Running the test program from [that forum post](https://discuss.codechef.com/t/bug-report-rust-code-is-being-compiled-in-debug-mode-without-optimization/24530) shows that the Rust optimizations issue is resolved now.

I have implemented a configuration sanity checker for D language too, which can be run in the codechef IDE mode:

```auto
import std.stdio, std.range, std.algorithm;

// Optimizing compilers should do tail call optimization here, so
// 0xBADF00D magic constant won't be found in stack if optimizations
// are enabled. Is there a cleaner way to detect optimizations?
bool detect_opt() {
  int[100] filler;
  bool detect_tail_call_opt(int depth, int magic) {
    if (depth > 100) {
      int x; foreach (i ; 20 .. 80) if (*(&x + i) == magic) return false;
      return true;
    }
    return detect_tail_call_opt(depth + 1, magic);
  }
  return filler[0] || detect_tail_call_opt(0, 0xBADF00D);
}

// GDC11 was the first version to start supporting getTargetInfo traits
bool detect_gdc11() {
  version(GNU) { return __traits(compiles,__traits(getTargetInfo, "cppStd")); }
  else return false;
}

void main() {
  bool assert_on = false, optimizations_on = detect_opt();
  version(assert) { assert_on = true; }
  string[] warnings;
  version(GNU) {
    writeln("Detected compiler: GDC");
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O3' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-frelease' option was not used!";
    if (detect_gdc11())
      warnings ~= "Note: GDC11 or newer may need '-flto' option, see https://gcc.gnu.org/PR102765";
  } else version(LDC) {
    writefln("Detected compiler: LDC (optimizing for %s)", __traits(targetCPU));
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-release' option was not used!";
    if (__traits(targetCPU) == "pentium4")
      warnings ~= "Performance warning: '-mcpu=native' option was not used!";
  } else version(DigitalMars) {
    writeln("Detected compiler: DMD");
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-release' option was not used!";
    warnings ~= "Performance warning: DMD generates much slower code than GDC or LDC!";
  } else {
    warnings ~= "Unknown compiler";
  }
  if (size_t.sizeof < 8)
    warnings ~= "Performance warning: not a 64-bit compiler!";
  if (warnings.empty)
    writeln("Everything seems to be properly configured.");
  else
    writeln(warnings.joiner("\n"));
}

```

Would it be possible to just quickly add **“-O3 -frelease”** options to the command line of your GDC 6.3 compiler?

There is no time limit multiplier for D and it’s treated as a high performance optimizing compiler with the same time limits as C++. Also looks like I’m the only remaining user of the D language on the codechef platform at the moment (based on checking submissions for a few recent contests). So the risk of making the users unhappy by breaking something is pretty low.

---

_[View the full topic](https://discuss.codechef.com/t/gdc-compiler-settings-on-codechef/95359)._
