Skip to content

Should --no-checks imply -DNDEBUG #28255

@jabraham17

Description

@jabraham17

In C code with assert, compiling with -DNDEBUG turns off asserts.

For example

#include <assert.h>
int main() {
  assert(0);
}

If this program is compiled without -DNDEBUG, it will fail. But compiling with -DNDEBUG disables the assert.

This can effect Chapel programs in a few ways

For example, consider this extern block

extern {
  #include <assert.h>
  void foo(void);
  void foo(void) {
    assert(0);
  }
}
foo();

There is no way to turn off this assert in a release build (technically --ccflags -DNDEBUG would work), meaning there is always going to be extra code generated for assert

This also affects includes

// file.h
#include <assert.h>
static void foo(void) {
  assert(0);
}
require "file.h";
extern proc foo();
foo();

In this code, there is no way to remove the assert in a default release build (--fast)?

Should we have --no-checks imply -DNDEBUG to turn off C assertions? We already do this in the runtime, when make OPTIMIZE=1 is used. But this only affects C code in the runtime, not C code included in other ways (e.g., require's, passed via the command line, extern blocks)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions