[llvm-bugs] [Bug 36599] New: __attribute__((format_arg(X)) is broken with ObjC message sends

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 5 07:54:34 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36599

            Bug ID: 36599
           Summary: __attribute__((format_arg(X)) is broken with ObjC
                    message sends
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bhamiltoncx at gmail.com
                CC: llvm-bugs at lists.llvm.org

I bisected this to https://reviews.llvm.org/D25820 / r284961 .

__attribute__((format_arg(X))) is supposed to mark a format argument as a
pass-through, but it no longer works with ObjC message sends.

Repro:

== apple clang-900.0.39.2: ok ==

% cat test.m
typedef unsigned int NSUInteger;

#define nil ((id)0)

@interface NSString
+ (id)stringWithFormat:(NSString *)fmt, ... __attribute__((format(__NSString__,
1, 2)));
@end

@interface NSBundle
- (NSString *)localizedStringForKey:(NSString *)key value:(nullable NSString
*)value table:(nullable NSString *)tableName __attribute__((format_arg(1)));
@end

#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment) \
  [bundle localizedStringForKey:(key) value:(val) table:(tbl)]

NSString *ShouldNotRaiseDataArgumentNotUsedByFormatString(NSUInteger count) {
  return [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(
          @"foo",
          @"",
          nil,
          @"%d",
          @""),
          count];
}

% clang --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

% clang -fsyntax-only -Werror test.m && echo OK || echo NOT OK
OK

== r317698: bad ==

% clang --version
clang version 6.0.0 (trunk 317696) (llvm/trunk 317698)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /src/install/bin

% cat test.m
typedef unsigned int NSUInteger;

#define nil ((id)0)

@interface NSString
+ (id)stringWithFormat:(NSString *)fmt, ... __attribute__((format(__NSString__,
1, 2)));
@end

@interface NSBundle
- (NSString *)localizedStringForKey:(NSString *)key value:(nullable NSString
*)value table:(nullable NSString *)tableName __attribute__((format_arg(1)));
@end

#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment) \
  [bundle localizedStringForKey:(key) value:(val) table:(tbl)]

NSString *ShouldNotRaiseDataArgumentNotUsedByFormatString(NSUInteger count) {
  return [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(
          @"foo",
          @"",
          nil,
          @"%d",
          @""),
          count];
}

% clang -fsyntax-only -Werror test.m && echo OK || echo NOT OK
test.m:23:11: error: data argument not used by format string
[-Werror,-Wformat-extra-args]
          count];
          ^
1 error generated.
NOT OK

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180305/896fc319/attachment.html>


More information about the llvm-bugs mailing list