Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,13 +1175,15 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__UINTMAX_C_SUFFIX__", ConstSuffix);
Builder.defineMacro("__UINTMAX_C(c)",
ConstSuffix.size() ? Twine("c##") + ConstSuffix : "c");
DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(LangAS::Default), Builder);
DefineFmt(LangOpts, "__PTRDIFF", TI.getPtrDiffType(LangAS::Default), TI,
Builder);
DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
DefineFmt(LangOpts, "__INTPTR", TI.getIntPtrType(), TI, Builder);
DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
// Use deduction to obtain the built-in __size_t and __ptrdiff_t types instead
// of standard integer types
Builder.defineMacro("__SIZE_TYPE__", "__typeof(sizeof(0))");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a good hold on whether this is a good idea or not. We should probably have an RFC for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I enhanced the check for the %zu format specifier in #143653, but some people reported that it generated a lot of false positives. As a result, the check was eventually removed. The reason was that calculating skb->len - sizeof(_arph) loses all the sugar types. If the PR gets accepted, I can add a new option to enable this enhanced check (under the condition that the libc defines size_t in this way).

DefineFmt(LangOpts, "__SIZE", TI.getSizeType(), TI, Builder);
Builder.defineMacro("__PTRDIFF_TYPE__", "__typeof((int*)0-(int*)0)");
DefineFmt(LangOpts, "__PTRDIFF", TI.getPtrDiffType(LangAS::Default), TI,
Builder);
DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
DefineTypeSizeAndWidth("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
Expand Down
Loading