From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19366 invoked from network); 18 Feb 2023 01:34:13 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 18 Feb 2023 01:34:13 -0000 Received: (qmail 15577 invoked by uid 550); 18 Feb 2023 01:34:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 15536 invoked from network); 18 Feb 2023 01:34:08 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pHawf8CkyxKpsrAIlpUwwScjwZtRBUFbG+lXEfrL1Rg=; b=xaYTPUunXVhbD4otkUsE0DRJ9Eca3DHfEYA645LpnZwkTbpNhTxF2jUwSuwlZqrEy6 Ws+LPj5CXVw35HkgprSrHmfumSCnnhqCP4Y8eiuUD0CNroOQhyXiGWCvhV/jfwRrbXKk YbW06TCO+5RXhjJMGVIR1+bZk7fakMt1Ki/fhO9AF7Q9nHFsuWB3IrEgCPenTeU4j5zB TIXfbEW7CZf5M9WLP1cxWcF8fXXrQ1sViegrZ/6Ur0NPXMCCNp2YV3x1e3Gn/rAOEHRo 0wLqxWr5bLL1quKzIP+zgjhc9vHsCroZazlvxMTDS8EskbPYtDKkzLvhASob6hAexh+1 V6og== X-Gm-Message-State: AO0yUKWZy2e6RnTdBSQhc5cLouZGt6wDzoCU79p3SlsahVV3VdWEF8GU 8DFQ5zBt8SXXBYlbyhY3JL2ljZOIy58= X-Google-Smtp-Source: AK7set/w7BNvXBUTtgS/mSd6cXx5uQhh7owYvZSrdXZss1RjoOhJHMUnl9osR+SKTOaB8xPukSrWpg== X-Received: by 2002:a17:902:e412:b0:19c:1450:8875 with SMTP id m18-20020a170902e41200b0019c14508875mr3418081ple.14.1676684036117; Fri, 17 Feb 2023 17:33:56 -0800 (PST) From: Fangrui Song To: musl@lists.openwall.com Cc: Fangrui Song Date: Fri, 17 Feb 2023 17:33:33 -0800 Message-Id: <20230218013333.844224-1-i@maskray.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] Use __builtin_FILE/__builtin_LINE if available C++ inline functions are requred to have exact same sequence of tokens in every translation unit, but __FILE__ and __LINE__ may expand to different tokens. The ODR violatioin is usually benign, but it can lead to errors when C++20 modules are used. echo 'import B; import C; int main() { foo(); }' > A.cc cat > B.ccm <<'eof' module; #include export module B; export inline void foo() { assert(1); } eof cat > C.ccm <<'eof' module; #include export module C; export inline void foo() { assert(1); } eof clang -std=c++20 --precompile B.ccm -o B.pcm clang -std=c++20 --precompile C.ccm -o C.pcm clang -std=c++20 -fprebuilt-module-path=. A.cc B.pcm C.pcm -o A /tmp/d/C.ccm:3:37: error: 'foo' has different definitions in different modules; definition in module 'C' first difference is function body export module C; export inline void foo() { assert(1); } ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ /tmp/d/B.ccm:3:37: note: but in 'B' found a different body export module B; export inline void foo() { assert(1); } ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ Fix this by preferring __builtin_FILE/__builtin_LINE which do not need preprocessing. --- include/assert.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/assert.h b/include/assert.h index d14ec94e..b209c2ae 100644 --- a/include/assert.h +++ b/include/assert.h @@ -4,6 +4,12 @@ #ifdef NDEBUG #define assert(x) (void)0 +#elif defined(__has_builtin) +#if __has_builtin(__builtin_FILE) +#define assert(x) ((void)((x) || (__assert_fail(#x, __builtin_FILE(), __builtin_LINE(), __func__),0))) +#else +#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) +#endif #else #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) #endif -- 2.39.GIT