mc-imperial / dredd

Framework for evaluating C/C++ compiler testing tools
Apache License 2.0
11 stars 3 forks source link

Compilation failure on MacOS #275

Closed afd closed 1 month ago

afd commented 1 month ago

The following code does not compile on MacOS according to the CI bots for #273. It compiles fine on Windows and Linux.

@ambergorzynski, @JonathanFoo0523, @JamesLee-Jones do any of you have Macs, and if so would you be able to try to compile this using Apple's clang++?

The MacOS error is:

tomutate.cc:59:11: error: expected ';' at end of declaration
  int a[4]{__dredd_replace_expr_int_constant(10, 5), __dredd_replace_expr_int_constant(11, 10), __dredd_replace_expr_int_constant(12, 15), __dredd_replace_expr_int_constant(13, 20)};

Here is the code:

#include <cinttypes>
#include <cstddef>
#include <functional>
#include <string>

#ifdef _MSC_VER
#define thread_local __declspec(thread)
#elif __APPLE__
#define thread_local __thread
#endif

static thread_local bool __dredd_some_mutation_enabled = true;
static bool __dredd_enabled_mutation(int local_mutation_id) {
  static thread_local bool initialized = false;
  static thread_local uint64_t enabled_bitset[1];
  if (!initialized) {
    bool some_mutation_enabled = false;
    const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION");
    if (dredd_environment_variable != nullptr) {
      std::string contents(dredd_environment_variable);
      while (true) {
        size_t pos = contents.find(",");
        std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos));
        if (!token.empty()) {
          int value = std::stoi(token);
          int local_value = value - 0;
          if (local_value >= 0 && local_value < 31) {
            enabled_bitset[local_value / 64] |= (static_cast<uint64_t>(1) << (local_value % 64));
            some_mutation_enabled = true;
          }
        }
        if (pos == std::string::npos) {
          break;
        }
        contents.erase(0, pos + 1);
      }
    }
    initialized = true;
    __dredd_some_mutation_enabled = some_mutation_enabled;
  }
  return (enabled_bitset[local_mutation_id / 64] & (static_cast<uint64_t>(1) << (local_mutation_id % 64))) != 0;
}

static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) {
  if (!__dredd_some_mutation_enabled) return arg;
  if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~(arg);
  if (__dredd_enabled_mutation(local_mutation_id + 1)) return -(arg);
  if (__dredd_enabled_mutation(local_mutation_id + 2)) return 0;
  if (__dredd_enabled_mutation(local_mutation_id + 3)) return 1;
  if (__dredd_enabled_mutation(local_mutation_id + 4)) return -1;
  return arg;
}

#include <iostream>

void foo() {
  const int b = __dredd_replace_expr_int_constant(2, 0);
  int a[4]{__dredd_replace_expr_int_constant(10, 5), __dredd_replace_expr_int_constant(11, 10), __dredd_replace_expr_int_constant(12, 15), __dredd_replace_expr_int_constant(13, 20)};
  if (!__dredd_enabled_mutation(30)) { std::cout << __dredd_replace_expr_int_constant(b, 25) << std::endl; }
}
JonathanFoo0523 commented 1 month ago

@afd I encountered the same error on my Mac.

sample.cc:59:11: error: expected ';' at end of declaration
  int a[4]{__dredd_replace_expr_int_constant(10, 5), __dredd_replace_expr_int_constant(11, 10), __dredd_replace_expr_int_constant(12, 15), __dredd_replace_expr_int_constant(13, 20)};
          ^
          ;
1 error generated.
JonathanFoo0523 commented 1 month ago

I am wondering if this is related to the c++ language standard. I can compile without problem with -std=c++17 option

afd commented 1 month ago

Ah, that will be it! The single file tests make use of a compiler options environment variable where this is set. We'll need to do the same for the execute tests. Good spot.

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: JFJJ @.> Sent: Friday, July 12, 2024 3:29:03 PM To: mc-imperial/dredd @.> Cc: Donaldson, Alastair F @.>; Mention @.> Subject: Re: [mc-imperial/dredd] Compilation failure on MacOS (Issue #275)

I am wondering if this is related to the c++ language standard. I can compile without problem with -std=c++17 option

— Reply to this email directly, view it on GitHubhttps://github.com/mc-imperial/dredd/issues/275#issuecomment-2225706205, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABEFEXPA7JV5T2FNPRFZGTTZL7R27AVCNFSM6AAAAABKYTGKA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRVG4YDMMRQGU. You are receiving this because you were mentioned.Message ID: @.***>

afd commented 1 month ago

Fixed by #273 and #277.