Skip to content

Commit

Permalink
Merged master:cd5ab56bc406 into amd-gfx:12107ad063b9
Browse files Browse the repository at this point in the history
Local branch amd-gfx 12107ad Merged master:f22ac1d15b1b into amd-gfx:e715bf7d18b5
Remote branch master cd5ab56 Change the default target CPU for OpenBSD/i386 to i586
  • Loading branch information
Sw authored and Sw committed Aug 8, 2020
2 parents 12107ad + cd5ab56 commit 3d52bae
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 47 deletions.
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,10 @@ def err_missing_atsign_prefix : Error<
def warn_objc_string_literal_comparison : Warning<
"direct comparison of a string literal has undefined behavior">,
InGroup<ObjCStringComparison>;
def warn_concatenated_literal_array_init : Warning<
"suspicious concatenation of string literals in an array initialization; "
"did you mean to separate the elements with a comma?">,
InGroup<DiagGroup<"string-concatenation">>;
def warn_concatenated_nsarray_literal : Warning<
"concatenated NSString literal for an NSArray expression - "
"possibly missing a comma">,
Expand Down Expand Up @@ -6142,6 +6146,9 @@ def warn_overloaded_shift_in_comparison :Warning<
def note_evaluate_comparison_first :Note<
"place parentheses around comparison expression to evaluate it first">;

def note_concatenated_string_literal_silence :Note<
"place parentheses around the string literal to silence warning">;

def warn_addition_in_bitshift : Warning<
"operator '%0' has lower precedence than '%1'; "
"'%1' will be evaluated first">, InGroup<ShiftOpParentheses>;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/Arch/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ std::string x86::getX86TargetCPU(const ArgList &Args,
return "x86-64";

switch (Triple.getOS()) {
case llvm::Triple::FreeBSD:
return "i686";
case llvm::Triple::NetBSD:
case llvm::Triple::OpenBSD:
return "i486";
case llvm::Triple::Haiku:
case llvm::Triple::OpenBSD:
return "i586";
case llvm::Triple::FreeBSD:
return "i686";
default:
// Fallback to p4.
return "pentium4";
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6906,6 +6906,21 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList,
<< DIE->getSourceRange();
Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
<< InitArgList[I]->getSourceRange();
} else if (const auto *SL = dyn_cast<StringLiteral>(InitArgList[I])) {
unsigned NumConcat = SL->getNumConcatenated();
// Diagnose missing comma in string array initialization.
// Do not warn when all the elements in the initializer are concatenated together.
// Do not warn for macros too.
if (NumConcat > 1 && E > 1 && !SL->getBeginLoc().isMacroID()) {
SmallVector<FixItHint, 1> Hints;
for (unsigned i = 0; i < NumConcat - 1; ++i)
Hints.push_back(FixItHint::CreateInsertion(
PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));

Diag(SL->getStrTokenLoc(1), diag::warn_concatenated_literal_array_init)
<< Hints;
Diag(SL->getBeginLoc(), diag::note_concatenated_string_literal_silence);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// CHECK-PG: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-PG: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-nopie" "-o" "a.out" "{{.*}}gcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lcompiler_rt" "-lpthread_p" "-lc_p" "-lcompiler_rt" "{{.*}}crtend.o"

// Check CPU type for i386
// RUN: %clang -target i386-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-i386-CPU %s
// CHECK-i386-CPU: "-target-cpu" "i586"

// Check CPU type for MIPS64
// RUN: %clang -target mips64-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64-CPU %s
Expand Down
104 changes: 104 additions & 0 deletions clang/test/Sema/string-concat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s

const char *missing_comma[] = {
"basic_filebuf",
"basic_ios",
"future",
"optional",
"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
"promise", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
"shared_future"
};

#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif

const wchar_t *missing_comma_wchar[] = {
L"basic_filebuf",
L"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
L"promise" // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
};

#if __cplusplus >= 201103L
const char *missing_comma_u8[] = {
u8"basic_filebuf",
u8"packaged_task" // expected-note{{place parentheses around the string literal to silence warning}}
u8"promise" // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
};
#endif

const char *missing_two_commas[] = {"basic_filebuf",
"basic_ios" // expected-note{{place parentheses around the string literal to silence warning}}
"future" // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
"optional",
"packaged_task"};

const char *missing_comma_same_line[] = {"basic_filebuf", "basic_ios",
"future" "optional", // expected-note{{place parentheses around the string literal to silence warning}}
"packaged_task", "promise"}; // expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}

const char *missing_comma_different_lines[] = {"basic_filebuf", "basic_ios" // expected-note{{place parentheses around the string literal to silence warning}}
"future", "optional", // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
"packaged_task", "promise"};

const char *missing_comma_same_line_all_literals[] = {"basic_filebuf", "future" "optional", "packaged_task"}; // expected-note{{place parentheses around the string literal to silence warning}}
// expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}

char missing_comma_inner[][4] = {
"a",
"b" // expected-note{{place parentheses around the string literal to silence warning}}
"c" // expected-warning{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
};


#define ONE(x) x
#define TWO "foo"
const char *macro_test[] = { ONE("foo") "bar",
TWO "bar",
"foo" TWO // expected-note{{place parentheses around the string literal to silence warning}}
}; // expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}

// Do not warn for macros.

#define BASIC_IOS "basic_ios"
#define FUTURE "future"
const char *macro_test2[] = {"basic_filebuf", BASIC_IOS
FUTURE, "optional",
"packaged_task", "promise"};

#define FOO(xx) xx "_normal", \
xx "_movable",

const char *macro_test3[] = {"basic_filebuf",
"basic_ios",
FOO("future")
"optional",
"packaged_task"};

#define BAR(name) #name "_normal"

const char *macro_test4[] = {"basic_filebuf",
"basic_ios",
BAR(future),
"optional",
"packaged_task"};

#define SUPPRESS(x) x
const char *macro_test5[] = { SUPPRESS("foo" "bar"), "baz" };

// Do not warn when all the elements in the initializer are concatenated together.
const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};

// Warning can be supressed also by extra parentheses.
const char *extra_parens_to_suppress_warning[] = {
"basic_filebuf",
"basic_ios",
"future",
"optional",
("packaged_task"
"promise"),
"shared_future"
};
2 changes: 1 addition & 1 deletion lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {

// Tell LTO not to eliminate these symbols.
sym->isUsedInRegularObj = true;
if (wrap->isDefined())
if (!wrap->isUndefined())
wrap->isUsedInRegularObj = true;
}
return v;
Expand Down
24 changes: 23 additions & 1 deletion lld/test/ELF/wrap-shlib-undefined.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: split-file %s %t.dir
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/main.s -o %t.o
# RUN: echo '.globl bar; bar: call __real_foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
# RUN: ld.lld -shared -soname=t.so %t1.o -o %t.so

Expand All @@ -19,7 +20,28 @@
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT UND bar
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT 6 foo

# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/wrap.s -o %twrap.o
# RUN: ld.lld -shared --soname=fixed %twrap.o -o %twrap.so
# RUN: ld.lld %t.o %twrap.so --wrap bar -o %t1
# RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=DYNSYM
# RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=ASM

## FIXME GNU ld does not export bar
# DYNSYM: Symbol table '.dynsym' contains 3 entries:
# DYNSYM: NOTYPE LOCAL DEFAULT UND
# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND bar
# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar

# ASM: <_start>:
# ASM-NEXT: callq {{.*}} <__wrap_bar@plt>

#--- main.s
.globl _start, foo
_start:
call bar
foo:

#--- wrap.s
.globl __wrap_bar
__wrap_bar:
retq
79 changes: 37 additions & 42 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ STATISTIC(NumSinkCommonCode,
STATISTIC(NumSinkCommonInstrs,
"Number of common instructions sunk down to the end block");
STATISTIC(NumSpeculations, "Number of speculative executed instructions");
STATISTIC(NumInvokes,
"Number of invokes with empty resume blocks simplified into calls");

namespace {

Expand Down Expand Up @@ -3956,17 +3958,36 @@ bool SimplifyCFGOpt::simplifyResume(ResumeInst *RI, IRBuilder<> &Builder) {
return false;
}

// Check if cleanup block is empty
static bool isCleanupBlockEmpty(iterator_range<BasicBlock::iterator> R) {
for (Instruction &I : R) {
auto *II = dyn_cast<IntrinsicInst>(&I);
if (!II)
return false;

Intrinsic::ID IntrinsicID = II->getIntrinsicID();
switch (IntrinsicID) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_label:
case Intrinsic::lifetime_end:
break;
default:
return false;
}
}
return true;
}

// Simplify resume that is shared by several landing pads (phi of landing pad).
bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
BasicBlock *BB = RI->getParent();

// Check that there are no other instructions except for debug intrinsics
// between the phi of landing pads (RI->getValue()) and resume instruction.
BasicBlock::iterator I = cast<Instruction>(RI->getValue())->getIterator(),
E = RI->getIterator();
while (++I != E)
if (!isa<DbgInfoIntrinsic>(I))
return false;
// Check that there are no other instructions except for debug and lifetime
// intrinsics between the phi's and resume instruction.
if (!isCleanupBlockEmpty(
make_range(RI->getParent()->getFirstNonPHI(), BB->getTerminator())))
return false;

SmallSetVector<BasicBlock *, 4> TrivialUnwindBlocks;
auto *PhiLPInst = cast<PHINode>(RI->getValue());
Expand All @@ -3987,17 +4008,8 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
if (IncomingValue != LandingPad)
continue;

bool isTrivial = true;

I = IncomingBB->getFirstNonPHI()->getIterator();
E = IncomingBB->getTerminator()->getIterator();
while (++I != E)
if (!isa<DbgInfoIntrinsic>(I)) {
isTrivial = false;
break;
}

if (isTrivial)
if (isCleanupBlockEmpty(
make_range(LandingPad->getNextNode(), IncomingBB->getTerminator())))
TrivialUnwindBlocks.insert(IncomingBB);
}

Expand All @@ -4017,6 +4029,7 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
PI != PE;) {
BasicBlock *Pred = *PI++;
removeUnwindEdge(Pred);
++NumInvokes;
}

// In each SimplifyCFG run, only the current processed block can be erased.
Expand All @@ -4035,28 +4048,6 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
return !TrivialUnwindBlocks.empty();
}

// Check if cleanup block is empty
static bool isCleanupBlockEmpty(Instruction *Inst, Instruction *RI) {
BasicBlock::iterator I = Inst->getIterator(), E = RI->getIterator();
while (++I != E) {
auto *II = dyn_cast<IntrinsicInst>(I);
if (!II)
return false;

Intrinsic::ID IntrinsicID = II->getIntrinsicID();
switch (IntrinsicID) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_label:
case Intrinsic::lifetime_end:
break;
default:
return false;
}
}
return true;
}

// Simplify resume that is only used by a single (non-phi) landing pad.
bool SimplifyCFGOpt::simplifySingleResume(ResumeInst *RI) {
BasicBlock *BB = RI->getParent();
Expand All @@ -4065,13 +4056,15 @@ bool SimplifyCFGOpt::simplifySingleResume(ResumeInst *RI) {
"Resume must unwind the exception that caused control to here");

// Check that there are no other instructions except for debug intrinsics.
if (!isCleanupBlockEmpty(LPInst, RI))
if (!isCleanupBlockEmpty(
make_range<Instruction *>(LPInst->getNextNode(), RI)))
return false;

// Turn all invokes that unwind here into calls and delete the basic block.
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) {
BasicBlock *Pred = *PI++;
removeUnwindEdge(Pred);
++NumInvokes;
}

// The landingpad is now unreachable. Zap it.
Expand Down Expand Up @@ -4102,7 +4095,8 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
return false;

// Check that there are no other instructions except for benign intrinsics.
if (!isCleanupBlockEmpty(CPInst, RI))
if (!isCleanupBlockEmpty(
make_range<Instruction *>(CPInst->getNextNode(), RI)))
return false;

// If the cleanup return we are simplifying unwinds to the caller, this will
Expand Down Expand Up @@ -4192,6 +4186,7 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
BasicBlock *PredBB = *PI++;
if (UnwindDest == nullptr) {
removeUnwindEdge(PredBB);
++NumInvokes;
} else {
Instruction *TI = PredBB->getTerminator();
TI->replaceUsesOfWith(BB, UnwindDest);
Expand Down
Loading

0 comments on commit 3d52bae

Please sign in to comment.